in reply to sed awk to perl help

For replacing this type of "one-liner" shell processing containing invocations of awk and sed with equivalent Perl code, I strongly suggest looking at perlrun. In this example it becomes something like:
perl -pipage.txt -ea -F"[;:]" 'my $out=shift @F;print "<a href=mysite. +net/$out>$out</a>\n";'
__________________________________________________________________________________

^M Free your mind!

Replies are listed 'Best First'.
Re^2: sed awk to perl help
by dcd (Scribe) on Apr 17, 2007 at 21:06 UTC
    When I tried this example, I had some problems with it, and I think there are 2 issues:

    1) the order of the arguments (I needed to order them as perl -paipage.txt -F"[;:]" -e to avoid the error

    Can't open my $out=shift @F;print "<a href=mysite.net/$out>$out</a>\n" +;: No such file or directory.

    and 2), the script didn't seem to handle multiple matches on the same line (that I think the original did)

    'map { print "<a href=mysite.net/$_>$_</a>\n" } @F'

    then I realized that this still didn't handle the way that awk deals with white space, so the one line got longer when I added split(" ",$_)

    perl -F"[:;]" -lane 'map { ($_)=split " ",$_; print "<a href=mysite.ne +t/$_ >$_</a>" } @F'

    given test data like

    a b ; d e : f g : ; x
      the -F specifies the split pattern, so instead of also splitting by ' ', just change the -F argument to  -F"[:;\s]"
      __________________________________________________________________________________

      ^M Free your mind!

      Key to hats: ^I=white ^B=black ^P=yellow ^E=red ^C=green ^M=blue - see Moron's scratchpad for fuller explanation.

        but splitting on spaces too early will change the results from the initial results, plus you won't get the special awk behaviour that you get when you split on <code>' '<\code>