Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: subroutine scalar string input

by 2teez (Vicar)
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

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 all is quiet...

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

    Results (126 votes). Check out past polls.