Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

The snippet I provided has nothing to do with opening files.

If you read the documentation for split in the links I provided, you'll see that split can take on several args or none:

split /regexp/, $splitstring, $quantity; split /regexp/, $splitstring; # quantity is assumed to be as many # as possible. split /regexp/; # $_ will be split up. split; # $_ will be split up as if the regex # looked like //.

print is a function, and thus, kinda likes to be called like this: print( "stuff" );. You can also call it like print "stuff";, but if the first thing to come after print is an opening parenthesis, print assumes that what follows is the args to the print function.

However, when you say (split), you're using the parens as a list constructor, to provide list context to split, not as a parameter set for print. So how do you specify to print that you want to treat the () as a list constructor or as grouping parens instead of as function parameter parens? You treat the parens as though they're part of an expression, by prepending the unary + sign.

Next, the [1,5] takes a slice of the list created by (split), returning only the 2nd and 6th elements.

This is all kind of idiomatic, which is why I recommend backing up a step and reading the docs. Once you've done that, you should have that lightbulb flick on and you'll catch on to what's going on.


In reply to Re^7: awk like question in perl by davido
in thread awk like question in perl by drock

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2023-12-10 10:04 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (39 votes). Check out past polls.