Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: subroutine scalar string input

by 2teez (Priest)
on Oct 20, 2012 at 23:51 UTC ( #1000160=note: print w/ replies, xml ) Need Help??

in reply to subroutine scalar string input

Hi robertw,

First of all, what you passed to the subroutrine is a scalar variable named $html not an html doc or html tag related string.
perlsub documentation, then gives a clear explanation of parameters passed to a subroutine as thus:

"The Perl model for function call and return values is simple: all functions are passed as parameters one single flat list of scalars, and all functions likewise return to their caller one single flat list of scalars. Any arrays or hashes in these call and return lists will collapse, losing their identities--but you may always use pass-by-reference instead to avoid this..."

So, within a subroutine the array @_ contains the parameters passed to that subroutine.
Thus this;

my $html = "hello"; routine($html); routine2($html); sub routine { my $greetings = shift @_; print $greetings; ## print hello } #OR sub routine2 { my ($greetings) = @_; print $greetings; ## print hello }
In case however, you intended to parse your imported html,
you may consider using an html parser module like HTML::TokeParser or HTML::TreeBuilder.
Hope this helps.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Comment on Re: subroutine scalar string input
Download Code
Replies are listed 'Best First'.
Re^2: subroutine scalar string input
by robertw (Sexton) on Oct 21, 2012 at 20:03 UTC
    thank you so much all of you this is very helpful:)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2015-11-29 14:24 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (751 votes), past polls