http://www.perlmonks.org?node_id=1000160


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:)