Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Perl substitution not working

by frozenwithjoy (Curate)
on Jun 21, 2012 at 00:44 UTC ( #977518=note: print w/ replies, xml ) Need Help??


in reply to Perl substitution not working

Well, the good news is that s/,,,/,/g should definitely work. The bad news is that your script is doing something weird. :P A couple things to be aware of:

  • you don't need to make @line an array. You can just write something like foreach my $line (@data).
  • you are using $line for both foreach loops. You are trying to use the same namespace for two different things. Maybe change the second one to foreach my $L1_line split...
  • Disregard this: The actual reason you aren't substituting properly is that you are printing @L1, but that array never gets modified by your substitution which acts on $line.


Comment on Re: Perl substitution not working
Select or Download Code
Re^2: Perl substitution not working
by muba (Priest) on Jun 21, 2012 at 00:53 UTC

    The actual reason you aren't substituting properly is that you are printing @L1, but that array never gets modified by your substitution which acts on $line.

    Not true:

    my @L1 = qw(Abc aBc abC); for my $line (@L1) { $line =~ s/a/_/i; print "\@L1: <", join(", ", @L1), ">; \$line: <$line>\n"; } __END__ @L1: <_bc, aBc, abC>; $line: <_bc> @L1: <_bc, _Bc, abC>; $line: <_Bc> @L1: <_bc, _Bc, _bC>; $line: <_bC>

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://977518]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2015-07-03 11:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (51 votes), past polls