Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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 the fog begins to lift...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2018-06-19 03:36 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.