Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Unable to split this line of code (printf warning)

by lepetitalbert (Abbot)
on Nov 24, 2005 at 21:45 UTC ( [id://511541]=perlquestion: print w/replies, xml ) Need Help??

lepetitalbert has asked for the wisdom of the Perl Monks concerning the following question:

Hello dear Monks,

I'm trying to split the following line of code :

printf ("\n\n %-70s" , "Creating printable report $ARGV[0].html ( ne +w ) ... ");

Tried

printf ("\n\n %-70s" , "Creating printable report" . "$ARGV[0].html ( new ) ... ");
printf ("\n\n %-70s" , "Creating printable report $ARGV[0].html ( new ) ... ");

added ()'s but always got 'printf (...) interpreted as function'.

I found it may have something to do with 'scalar/list context' or missing brackets, but not the way to solve the prob.

Thanks

Have a nice day

"There is only one good, namely knowledge, and only one evil, namely ignorance." Socrates

Replies are listed 'Best First'.
Re: Unable to split this line of code (printf warning)
by GrandFather (Saint) on Nov 24, 2005 at 21:51 UTC

    Just remove the (). The warning says it all: printf looks like a function because of the () around the argument list.

    printf "\n\n %-70s" , "Creating printable report $ARGV[0].html ( new + ) ... ";

    DWIM is Perl's answer to Gödel

      Hello,

      Thanks a lot. I'm not familiar with those warning message.

      Almost gone crazy.

      Have a nice day.

      "There is only one good, namely knowledge, and only one evil, namely ignorance." Socrates
Re: Unable to split this line of code (printf warning)
by monarch (Priest) on Nov 24, 2005 at 22:43 UTC
    I tried this out myself, and it's a new one to me, silly Perl!

    Your statement works fine if you ensure there's no space between the function name and the opening parenthesis. i.e: "printf(" works but "printf (" fails.

    I'd say this is a shortcoming in the perl interpreter. You were using valid syntax all along.. it's just that it seems perl doesn't like the whitespace in this situation..

      It's not a shortcoming of the interpreter; it's the ambiguousness of using the same symbols for two different purposes. It can't read your mind to know whether you want to group an expression with parentheses for precedence purposes or use the parentheses to group the arguments to the operator.

      I suggest not using a space between a function name and the opening parenthesis.

Re: Unable to split this line of code (printf warning)
by Aristotle (Chancellor) on Nov 26, 2005 at 00:40 UTC

    That warning is there because someone who writes

    print (2+3)*5;

    probably meant

    print((2+3)*5);

    but what they actually get is

    (print(2+3))*5;

    The warning is both silly and sensible, because the subtle ambiguity in the syntax that it’s about can’t be resolved in any reasonable fashion. Life’s a crapshoot, sometimes.

    So either get used to not putting a space between the function and its paren despite your preferences, or say no warnings 'misc'; and risk missing useful warnings. Life’s a crapshoot, sometimes.

    Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-25 16:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found