Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^5: Why can't I use s///

by linuxer (Deacon)
on May 08, 2013 at 21:52 UTC ( #1032684=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Why can't I use s///
in thread Why can't I use s///

What do you mean with "does not work"?

Any errors? Which ones? Which messages? Any warnings? Which ones? Please be more specific with your error descriptions.

Spend some spaces, so you can visually separate inline comments from code, this may help to better see the "error"...

my $cgi = CGI->new; # Instantiate a +CGI class print $cgi->header, # First we creat +e a header $cgi->start_html('My first Perl website'), # Begin HTML pag +e $cgi->h1('Success'), # create the Tag + <h1>TEXT</h1> my $text="../files/jack/2012/derpone.pdf"; $text = basename($text); $cgi->p($text),
Your are printing a list of items:
  • result of $cgi methods: header, start_html, h1
  • result of a string-assignment to the scalar $text (oops!?!)

And the print is done, as the semicolon behind my $text = "...path" terminates print's argument list.

The final $cgi->p($text); is executed in void context and therefor not printed!

Watch out where your commas and semicolons are!

But apart from the technical issue:

Why do you want to mix printing and (initializing and ) processing data?

Better do it step by step:

  1. Prepare your data,
  2. print your data.

Although one could mix it, I don't think it's a good idea to do so.

Keep it the way as your first example shows it (but spend some spaces as well).

edit: fixed ordered list


Comment on Re^5: Why can't I use s///
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1032684]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2014-11-01 10:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (229 votes), past polls