Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Just Another Perl Article

by japhy (Canon)
on Nov 02, 2001 at 00:19 UTC ( [id://122660]=perlmeditation: print w/replies, xml ) Need Help??

I've been asked by Jonathan M. Hollin (of the West Yorkshire Perl Mongers) to provide some nifty Perl articles for the WYPM web site, so I've gotten back into the article-writing-shindig. It's a general column (for no group in particular) called "Just Another Perl Article". The first article is "Getting a Handle on Files", and covers some filehandle tricks (and a bit of obfuscation). If you find it useful, you can go ahead and use it for whatever purpose you see fit (so long as you keep the file intact).

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Just Another Perl Article
by stefan k (Curate) on Nov 02, 2001 at 15:06 UTC
    Hi :-),
    this was a pretty cool read! I learned a lot from it. Thanks.

    One question though: I don't really get this little piece of code:

    $\ = $/; # ORS = IRS = "\n" $, = ":"; # OFS = "," while (<PASSWD>) { chomp; # removes $/ from $_ my @f = split $,; # splits $_ on occurrences of $, # fool around with @f print MOD @f; }
    Why would it put a newline to the end of each line during the print? You say that "$\ goes where you put a \n in your print()" but you're chomp()ing the newlines.

    What do I miss here?

    Hmm, now looking at it I get even more questionmarks on my forehead:

    1. What's the point of assigning a colon to $, when split doesn't use it by default?
    2. Why do you have to assign $\ with $/? Aren't they supposed to have the same value anyway?
    3. Why don't we have an abbrev like <c> for the code-Tag, since it is really much to type *grin*?

    Still, as I said above: good read!

    Regards... Stefan
    you begin bashing the string with a +42 regexp of confusion

    ps: a typo in your article:

    $ARGV this holds the input source currently begin read from
    should probably be "being read from", er?
      • $/ is the input record separator. This is "\n" by default.
      • $\ is the output record separator. This is the empty string by default. Setting it to $/ means that you no longer need to put a "\n" on the end of each print statement.
      • $, is the string that is output between each element of the list passed to print. The default value is the empty string. By setting it to ":" we don't just control the split statement, but also the print statement. The elements of @f are printed separated by ":" characters.

      Does that help? You can get more info on special Perl variables like these in perlvar.

      --
      <http://www.dave.org.uk>

      "The first rule of Perl club is you don't talk about Perl club."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://122660]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-26 02:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found