Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Writing to text file

by sundialsvc4 (Abbot)
on Dec 14, 2010 at 14:26 UTC ( #877084=note: print w/replies, xml ) Need Help??

in reply to Writing to text file

The “immediate-IF” syntax can come in handy here:   ( expression ? value_if_true : value_if_false )

Another handy way to do it would be to define a little sub such as:

sub quoted { my $value = shift; if (defined($value)) { return "\"$value\""; } else { return ""; } }

Now you can print calls to this function.   It will return a quoted string if there’s anything inside, or an empty-string if not.   This kind of “shorthand” if applicable, can make code much easier to read.

Replies are listed 'Best First'.
Re^2: Writing to text file
by Your Mother (Bishop) on Feb 09, 2018 at 06:58 UTC

    Code that compiles? When did this era end? For the benefit of posterity I must point out it's naïve and broken; handling quoting properly is not really a trivial problem–

    print quoted('"quoted"'), $/;

    And immediate if is a very un-Perly name for the ternary operator.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://877084]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2018-03-21 13:24 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (267 votes). Check out past polls.