SPUG: reg pattern matching in a loop
Craig Steffler
seaperldev at gmail.com
Fri Oct 14 20:00:54 PDT 2011
Actually you probably want something more like this:
$_ =~ s/\s+/|/g; # this will substitute all multiple instances with a
single pipe but if you actually want each space substituted you'd need $_ =~
s/\s/|/g;
Also when you want to avoid backslashitis you can do something like
s#\s+#|#g which is kind of hard to read but it's basically s # \s+ # | #
g; so just ignore the spaces
(of course there's a setting that ignores white space to i your expression
as well).
Even s{\s+}{|}g can be used.
On Fri, Oct 14, 2011 at 12:35 PM, Ramon Hildreth <ramonred at gmail.com> wrote:
> Esteemed colleges, I have recently re-opened my mental archives and am
> attempting to create some scripts at work using perl to create some
> utilities we need for our Lawson system. I am having trouble with doing a
> pattern match/substitution by line in a while loop -
>
> ........
>
> open (OUTPUT, ">>$OUTPUTFILE");
>
> while (<INPUT>)
> {
> $_ =~ s/ \ +/|/;
> print OUTPUT "$PRODUCTLINE $_";
> }
> ..........
>
> my code works fine without the substitution listed above the print
> statement, what I'm attempting to do it for each line is to remove all
> spaces and replace with a pipe (|) - when I do leave this bit a code it, it
> appears to be ignored. I done a lot of googling and dusting off copies of
> perl books, but so far no luck in the context I'm working with. Any help
> would be greatly appreciated.
>
> Thank You.
>
> Ramon
>
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
> POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays
> WEB PAGE: http://seattleperl.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/spug-list/attachments/20111014/220d3a00/attachment-0001.html>
More information about the spug-list
mailing list