Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by linuxer (Curate)
on May 08, 2013 at 21:52 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-03-28 11:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found