PilotinControl has asked for the wisdom of the Perl Monks concerning the following question:
Good Afternoon Monks,
My question is not so much a question but an explanation is needed concerning the following code:
#!/usr/bin/perl -w use strict; use warnings; my $file = "data.txt"; local $^I = ".bak"; local @ARGV = ($file); while (<>) { chomp; my @field = split(':'); if ($field[1] =~ s/E/L/g) { print "$field[0]:$field[1]\n"; } elsif ($field[1] =~ s/L/E/g) { print "$field[0]:$field[1]\n"; } else { print "$_\n"; } } unlink("$file.bak"); print "UPDATED!!"; sleep 5; exit(); __DATA__ 1:E 2:L 3:L
As you can see once the code is executed it does change the L to an E and vice versa. My question is why is it saying use of uninitialized value in $field1 in substitution ring when in fact $field1 does have a value? Thanks for the clarification.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Uninitialized Value
by choroba (Cardinal) on May 18, 2015 at 16:32 UTC | |
by PilotinControl (Pilgrim) on May 18, 2015 at 16:47 UTC | |
by pme (Monsignor) on May 18, 2015 at 16:53 UTC | |
by Athanasius (Archbishop) on May 18, 2015 at 17:27 UTC | |
by PilotinControl (Pilgrim) on May 18, 2015 at 18:14 UTC | |
by vinoth.ree (Monsignor) on May 18, 2015 at 17:30 UTC | |
by marinersk (Priest) on May 18, 2015 at 19:13 UTC | |
by Not_a_Number (Prior) on May 18, 2015 at 20:07 UTC | |
|
Re: Uninitialized Value
by Not_a_Number (Prior) on May 18, 2015 at 17:25 UTC | |
|
Re: Uninitialized Value
by GotToBTru (Prior) on May 18, 2015 at 16:50 UTC | |
by PilotinControl (Pilgrim) on May 18, 2015 at 18:12 UTC | |
by GotToBTru (Prior) on May 18, 2015 at 18:19 UTC |