IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Use Perl.
Are they always in order and the values guaranteed to be true? If so, then the following hack will work:
\nperl -pe 'if (/^foo(\\d+)=(.*\\n)/) {$r ||= $2; $_="foo4=$r" if 4==$1;}' testdata\n

If the values are not guaranteed to be true, then you have to check whether $r is defined before assigning to it. If they are not always in order then I'd need to run 2 passes and would want to write a simple script to do it.

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New have time for some education?
perl -pe 'if (/^foo(\\d+)=(.*\\n)/) {$r ||= $2; $_="foo4=$r" if 4==$1;}' testdata notice I am using ttffp tags
now I want to be sure I clearly understand what is going on. I throw my file at this string
perl -pPrint -eEdit single tick to resolve the following enclosed actions

if (what is the / before the first foo? ^foo followed by a decimal place holder and has a .* followed by a newline and the closing /?
$r is replace || (why the 2 pipes? $2 being the second field $_"foo4=$r(eplaced value) if 4 is exactly equal to $1 the first field. ending tick

corrections and information gladly accepted,
thanx,
bill
All tribal myths are true, for a given value of "true" Terry Pratchett
[link|http://boxleys.blogspot.com/|http://boxleys.blogspot.com/]

Any opinions expressed by me are mine alone, posted from my home computer, on my own time as a free american and do not reflect the opinions of any person or company that I have had professional relations with in the past 48 years. meep
questions, help? [link|mailto:pappas@catholic.org|email pappas at catholic.org]
New Here is the same code, commented
\n#!/usr/bin/perl -p\n# The -p switch, as explained in perlrun, reads each\n# line into $_, runs your code, then prints $_.\n# More precisely it puts a loop like this around your\n# code:\n#\n#   LINE:\n#     while (<>) {\n#       ...             # your program goes here\n#     } continue {\n#       print or die "-p destination: $!\\n";\n#     }\n#\n# The -p switch allows you to edit lines on the fly by\n# editing $_.\n#\n# Previously I used -e to allow the program to go on\n# the command line, but this time around I am not\n# doing that.\n\nif (\n  /              # This regular expression matches:\n    ^            #   the start of the string\n    foo          #   then foo\n    (\\d+)        #   then some digits, put in $1\n    =            #   an = sign\n    (.*\\n)       #   other junk, including a return\n                 #     that go into $2.\n  /x             # /x turns on commenting.\n                 # (since no variable is bound to the\n                 # match it matches $_ - which is\n                 # conveniently your current line.)\n) {\n  # OK, we matched.  If we have not yet come up with\n  # a replacement for foo4, then set it to $2.\n  $r ||= $2;\n  # If this is foo4, then replace $_ (the new value is\n  # what we'll print).\n  $_ = "foo4$r" if 4 == $1;\n}\n

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New thank you very much
knowing how it works sort of is no where near as good as knowing exactly why it works so can put that to use elsewhere,
thanx,
bill
All tribal myths are true, for a given value of "true" Terry Pratchett
[link|http://boxleys.blogspot.com/|http://boxleys.blogspot.com/]

Any opinions expressed by me are mine alone, posted from my home computer, on my own time as a free american and do not reflect the opinions of any person or company that I have had professional relations with in the past 48 years. meep
questions, help? [link|mailto:pappas@catholic.org|email pappas at catholic.org]
     scripting skills are muy rusty(edited for fsckin tttags) - (boxley) - (9)
         Flippin' 'eck, box. - (pwhysall) - (4)
             WTF are you doing up at this ungodly hour? Go back to bed! -NT - (CRConrad) - (3)
                 Up'n'at 'em, that's me! -NT - (pwhysall) - (2)
                     Shudder. -NT - (CRConrad) - (1)
                         Pervert. -NT - (pwhysall)
         Use Perl. - (ben_tilly) - (3)
             have time for some education? - (boxley) - (2)
                 Here is the same code, commented - (ben_tilly) - (1)
                     thank you very much - (boxley)

The fat Penguin is back stage putting on her Valkyrie costume and warming up her voice, even as we speak.
98 ms