[32075] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3339 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 30 14:09:25 2011

Date: Wed, 30 Mar 2011 11:09:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 30 Mar 2011     Volume: 11 Number: 3339

Today's topics:
    Re: pattern matching and abstract functions <tadmc@seesig.invalid>
    Re: pattern matching and abstract functions <willem@toad.stack.nl>
    Re: pattern matching and abstract functions <cartercc@gmail.com>
    Re: pattern matching and abstract functions <willem@toad.stack.nl>
    Re: pattern matching and abstract functions <uri@StemSystems.com>
    Re: REVISED: Variable length array to XML <thepoet_nospam@arcor.de>
    Re: REVISED: Variable length array to XML <uri@StemSystems.com>
    Re: REVISED: Variable length array to XML <thepoet_nospam@arcor.de>
    Re: REVISED: Variable length array to XML <uri@StemSystems.com>
    Re: Search script to index dynamic pages <rdw204@gmail.com>
    Re: Search script to index dynamic pages <tadmc@seesig.invalid>
        strange behaviour w.r.t get function <rahul_vasishta@yahoo.co.in>
    Re: strange behaviour w.r.t get function <tadmc@seesig.invalid>
    Re: strange behaviour w.r.t get function <rahul_vasishta@yahoo.co.in>
    Re: strange behaviour w.r.t get function <willem@toad.stack.nl>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 29 Mar 2011 23:02:55 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: pattern matching and abstract functions
Message-Id: <slrnip5ai9.qdb.tadmc@tadbox.sbcglobal.net>

ccc31807 <cartercc@gmail.com> wrote:
> On Mar 29, 5:56 pm, Tad McClellan <ta...@seesig.invalid> wrote:
>> my %action = (
>>     home    => \&do_this,
>>     faq     => \&do_that,
>>     links   => \&do_something_else,
>>     contact => \&do_another_thing,
>> );
>
> I haven't tried this yet, so this may be off, but it looks like you
> have constructed a hash with keys matching the value of the parameter
> containing the user selected value (e.g., home, faq, etc.), and a
> reference to the function to be triggered according to the value of
> the key.
>
> I can deal with this, but it will require me to think of a name for
> each function ... not too difficult since I can use the value of the
> parameter (like menu, faq, etc.). However, I was really looking for
> something that triggered on the value of the parameter itself.

magic_sub() below triggers on its argument.


    my $some_return_value = magic_sub{$menu};
    ...
    sub magic_sub {
        my $sub = $action{shift()};
        return $sub->();
    }

> The only other thing, that I didn't mention, is that this is an
> interface for a database, and we potentially have 20 or 30 variables
> coming in (to insert a person into PERSON, for example). I'm using
> lexical variables for these values, and this has never been a problem.
> The functions call DBI functions and pass in the action (select,
> insert, update, delete) and the relevant data, and I don't see any
> need whatsoever to make any change in that code.


Did someone somewhere suggest that you make a change in that code?

If so, you should quote a bit where they suggested it, and then
add your comment.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


------------------------------

Date: Wed, 30 Mar 2011 07:50:49 +0000 (UTC)
From: Willem <willem@toad.stack.nl>
Subject: Re: pattern matching and abstract functions
Message-Id: <slrnip5o6p.1air.willem@toad.stack.nl>

ccc31807 wrote:
) Let's suppose you have a web app, and your HTML user interface
) contains menu items like this:
) <a href="site?menu=home">HOME</a>
) <a href="site?menu=faq">FAQ</a>
) <a href="site?menu=links">LINKS</a>
) <a href="site?menu=contact">CONTACT US</a>
)
) On the server side, you have code that looks like this (as STYLE A):
) use CGI;
) my $menu = param('menu');
) if ($menu eq 'home') { do_this(); }
) elsif ($menu eq 'faq') { do_that(); }
) elsif ($menu eq 'links') { do_something_else(); }
) elsif ($menu eq 'contact') { do_another_thing(); }
) else { print "CGI ERROR, unknown $menu\n"; }
)
) Some languages (Lisp and Erlang, for instance) have functions that are
) conceptually overloaded and specialized according to their parameters.
) For example, using a Perlish hypothetical language, you might do this
) (as STYLE B):
) do_this('home');
) do_this('faq');
) do_this('links');
) do_this('contact');
) do_this(_); # underscore represents an unknown value

Could you give a *complete* example of how the function declaration
of do_this would look in Lisp or Erlang ?

) Is there any way to specialize functions in Perl based on the value of
) their parameters? The app is written in a procedural style, not OO,
) and I'd like a way to introduce polymorphism without rewriting it as
) an OO app.

You can do this:

use do_this;
my $menu = param('menu');
do_this->$menu();

And then have functions in the do_this package named for each menu.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


------------------------------

Date: Wed, 30 Mar 2011 06:48:04 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: pattern matching and abstract functions
Message-Id: <52be7b93-9625-4944-b029-7f26377df6de@18g2000prd.googlegroups.com>

On Mar 29, 6:41=A0pm, "Uri Guttman" <u...@StemSystems.com> wrote:
> so? you can call any sub via a dispatch table. you can even pass in
> extra args or whatever in the calling call. the main idea is just using
> a key (your input value NOT TYPE) to decide which sub to call. i said
> google for many discussion on dispatch tables over many years.

I was really, really looking for something like Erlang type multi
functions, where you can do the following:

cost(orange) -> 4;
cost(apple) -> 5;
cost(banana) -> 6;
cost(apple) -> 7;
cost(_) -> unknown.

If you call cost(X), you get the cost of X  -- simple, straight
forward pattern matching, and it doesn't matter whether X is an apple,
orange, or anything else.

Yes, I know that different languages are optimized for different
things. They say about Erlang that it makes hard things easy and easy
things hard, and I can vouch for the truth of that from hard won
personal experience.

Unfortunately, I don't know enough about language construction in
general, or Perl in particular, to understand how something like this
could work in Perl, but I'm happy with the dispatch table syntax. Now,
I'm going to play with it so I'll probably be tied up for most of the
rest of the day ... and besides ... I've also got to do some few
little things for my employer so he won't have an excuse to fire
me. ;-)

CC.


------------------------------

Date: Wed, 30 Mar 2011 14:18:53 +0000 (UTC)
From: Willem <willem@toad.stack.nl>
Subject: Re: pattern matching and abstract functions
Message-Id: <slrnip6eud.2t9t.willem@toad.stack.nl>

ccc31807 wrote:
) On Mar 29, 6:41?pm, "Uri Guttman" <u...@StemSystems.com> wrote:
)> so? you can call any sub via a dispatch table. you can even pass in
)> extra args or whatever in the calling call. the main idea is just using
)> a key (your input value NOT TYPE) to decide which sub to call. i said
)> google for many discussion on dispatch tables over many years.
)
) I was really, really looking for something like Erlang type multi
) functions, where you can do the following:
)
) cost(orange) -> 4;
) cost(apple) -> 5;
) cost(banana) -> 6;
) cost(apple) -> 7;
) cost(_) -> unknown.

Why are you trying to shoehorn Erlang-specific language constructs into
other languages ?  The above is not in any way better than any of the ways
it can be done in Perl or any other language.

) Yes, I know that different languages are optimized for different
) things. They say about Erlang that it makes hard things easy and easy
) things hard, and I can vouch for the truth of that from hard won
) personal experience.

Except that it is *not easier* to do this the Erlang way, except
for you because you happen to be used to doing it like that.


But, if you really really want to, I'm sure that Perl can be taught to
do it almost exactly like the above.

There are ways to hook into the language parser so that you
can add extra constructs, and basides that, you could probably
come quite close by tie-ing a hash or something.

This should work:

tie %cost, tiefunction;

my $x = 1;
$cost{orange} = sub { 4 };
$cost{apple} = sub { 5 };
$cost{banana} = sub { $x++ };
$cost{apple} = sub { 7 };

say $cost{banana}; # 1
say $cost{apple};  # 7
say $cost{banana}; # 2
say $cost{pear};   # undef

package tiefunction; # Left as an exercise to the reader.
                     # In other words: I'm too lazy.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


------------------------------

Date: Wed, 30 Mar 2011 13:00:24 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: pattern matching and abstract functions
Message-Id: <87ei5oa6hj.fsf@quad.sysarch.com>

>>>>> "c" == ccc31807  <cartercc@gmail.com> writes:

  c> On Mar 29, 6:41 pm, "Uri Guttman" <u...@StemSystems.com> wrote:
  >> so? you can call any sub via a dispatch table. you can even pass in
  >> extra args or whatever in the calling call. the main idea is just using
  >> a key (your input value NOT TYPE) to decide which sub to call. i said
  >> google for many discussion on dispatch tables over many years.

  c> I was really, really looking for something like Erlang type multi
  c> functions, where you can do the following:

  c> cost(orange) -> 4;
  c> cost(apple) -> 5;
  c> cost(banana) -> 6;
  c> cost(apple) -> 7;
  c> cost(_) -> unknown.

and that is a dispatch table with a different syntax. also it seems your
code example is really a hash as the values are just constants.

  c> If you call cost(X), you get the cost of X  -- simple, straight
  c> forward pattern matching, and it doesn't matter whether X is an apple,
  c> orange, or anything else.

it isn't calling different code based upon the input, it is just looking
up values. in perl that is just a hash.

  c> Unfortunately, I don't know enough about language construction in
  c> general, or Perl in particular, to understand how something like this
  c> could work in Perl, but I'm happy with the dispatch table syntax. Now,
  c> I'm going to play with it so I'll probably be tied up for most of the
  c> rest of the day ... and besides ... I've also got to do some few
  c> little things for my employer so he won't have an excuse to fire
  c> me. ;-)

a dispatch table is easy, fast and very flexible. it is what you want.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Wed, 30 Mar 2011 06:49:39 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: REVISED: Variable length array to XML
Message-Id: <4d92b665$0$7651$9b4e6d93@newsspool1.arcor-online.net>

Am 29.03.2011 22:51, schrieb Uri Guttman:
>>>>>> "DP" == Don Pich<dpich@polartel.com>  writes:
>
>    DP>  my %hash;
>    DP>  foreach my $leaf (@final) {
>    DP>     my $ptr = \%hash;
>    DP>     foreach my $i ( 0 .. $#$leaf - 1 ) {
>    DP>       my $node = $leaf->[$i];
>    DP>       if( $i != $#$leaf - 1 ) {
>    DP>         $ptr->{$node} = {}
>    DP>           unless( exists $ptr->{$node} );
>    DP>         $ptr = $ptr->{$node};
>    DP>       } else {
>    DP>         $ptr->{$node} = $leaf->[$i + 1];
>
> learn about autovivification. there is no need to manually make a hash
> ref if one doesn't exist. assume it does and perl creates it for you.

As the one who wrote that piece of code I've got to add my
2 Ct here. Perl does do autovivication, but in this case it
will not DWIM.
     $ptr = $ptr->{$node};
will *not* autovivicate a hash entry with the key "$node". There is
neither an assignment to the hash entry, nor does the code try to
access a deeper entry that would bring intermediate entries to life.

Making $ptr point to an undef value (that would happen with each
iteration if the hash ref wasn't assigned manually), perl *would*
autovivicate a hash reference - but it would have no association
with our %hash, and only in the last inner iterations would the
(short-lived) referenced hash even hold an entry with the key "$node".

Or more concise from perlfaq4:
| Normally, merely accessing a key's value for a nonexistent key
| does *not* cause that key to be forever there.

-Chris


------------------------------

Date: Wed, 30 Mar 2011 01:49:44 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: REVISED: Variable length array to XML
Message-Id: <87lizxb1jb.fsf@quad.sysarch.com>

>>>>> "CW" == Christian Winter <thepoet_nospam@arcor.de> writes:

  CW> Am 29.03.2011 22:51, schrieb Uri Guttman:
  >>>>>>> "DP" == Don Pich<dpich@polartel.com>  writes:
  >> 
  DP> my %hash;
  DP> foreach my $leaf (@final) {
  DP> my $ptr = \%hash;
  DP> foreach my $i ( 0 .. $#$leaf - 1 ) {
  DP> my $node = $leaf->[$i];
  DP> if( $i != $#$leaf - 1 ) {
  DP> $ptr->{$node} = {}
  DP> unless( exists $ptr->{$node} );
  DP> $ptr = $ptr->{$node};
  DP> } else {
  DP> $ptr->{$node} = $leaf->[$i + 1];
  >> 
  >> learn about autovivification. there is no need to manually make a hash
  >> ref if one doesn't exist. assume it does and perl creates it for you.

  CW> As the one who wrote that piece of code I've got to add my
  CW> 2 Ct here. Perl does do autovivication, but in this case it
  CW> will not DWIM.
  CW>     $ptr = $ptr->{$node};
  CW> will *not* autovivicate a hash entry with the key "$node". There is
  CW> neither an assignment to the hash entry, nor does the code try to
  CW> access a deeper entry that would bring intermediate entries to life.

true. i didn't delve into the logic much. it was the 
	$ptr->{$node} = {}
line which i was triggered on. that is almost never needed due to
autoviv. the fact that his code didn't use that was confusing. in fact
it is odd what he is doing there. why do $ptr = $ptr->{$node}; ? it just
gets the new anon hash into $ptr. i can't make head nor tail of what he
is trying to do in that loop.

  CW> Making $ptr point to an undef value (that would happen with each
  CW> iteration if the hash ref wasn't assigned manually), perl *would*
  CW> autovivicate a hash reference - but it would have no association
  CW> with our %hash, and only in the last inner iterations would the
  CW> (short-lived) referenced hash even hold an entry with the key "$node".

i was making that same point in a recent thread on autoviv and i know it
well. the code is just too odd looking anyhow. as i keep telling him,
use a templater.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Wed, 30 Mar 2011 08:46:35 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: REVISED: Variable length array to XML
Message-Id: <4d92d1ce$0$7659$9b4e6d93@newsspool1.arcor-online.net>

Am 30.03.2011 07:49, schrieb Uri Guttman:
>>>>>> "CW" == Christian Winter<thepoet_nospam@arcor.de>  writes:
 >
> true. i didn't delve into the logic much. it was the
> 	$ptr->{$node} = {}
> line which i was triggered on. that is almost never needed due to
> autoviv. the fact that his code didn't use that was confusing. in fact
> it is odd what he is doing there. why do $ptr = $ptr->{$node}; ? it just
> gets the new anon hash into $ptr. i can't make head nor tail of what he
> is trying to do in that loop.

It's basically just like a pointer in a C-style tree. At first
it points to the root node, then with each iteration a child node
gets added (if not already there) and the pointer is moved to point to
this child. The fact that it uses the name of a hash key instead of
a C struct member's name is just a variation of the concept.

>    CW>  Making $ptr point to an undef value (that would happen with each
>    CW>  iteration if the hash ref wasn't assigned manually), perl *would*
>    CW>  autovivicate a hash reference - but it would have no association
>    CW>  with our %hash, and only in the last inner iterations would the
>    CW>  (short-lived) referenced hash even hold an entry with the key "$node".
>
> i was making that same point in a recent thread on autoviv and i know it
> well. the code is just too odd looking anyhow. as i keep telling him,
> use a templater.

I'm not convinced that a template system is the only answer to
the problem. A CSV module and Hash::Merge would be enough to populate
the hash structure, and one of the numerous xml modules should be
able to output what he wants - though that could be done in a few
lines of code as well. In fact, it should be nothing more than

dump_hash(\%hash);

sub dump_hash
{
   my($h, $ind) = @_;
   my $indent = "  " x $ind;
   return (ref $h eq "HASH") ?
     join('', map {
       $indent . "<$_>" . $/ .
       dump_hash($h->{$_}, $ind + 1) .
       $indent . "</$_>" . $/
     } keys %$h)
     :
     $indent . $h . $/;
}

I myself would, of course, use appropriate modules for production
code which check for corner cases and provide sensible error messages,
but the OPs problem and the possible solutions do make for a fine
academic task to learn about (or toy around with) topics like hashes,
references, recursion, top-down vs. bottom-up concepts or variable
depth algorithms.

-Chris


------------------------------

Date: Wed, 30 Mar 2011 03:27:49 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: REVISED: Variable length array to XML
Message-Id: <87aagdawzu.fsf@quad.sysarch.com>

>>>>> "CW" == Christian Winter <thepoet_nospam@arcor.de> writes:

  CW> Am 30.03.2011 07:49, schrieb Uri Guttman:
  >>>>>>> "CW" == Christian Winter<thepoet_nospam@arcor.de>  writes:
  >> 
  >> true. i didn't delve into the logic much. it was the
  >> $ptr->{$node} = {}
  >> line which i was triggered on. that is almost never needed due to
  >> autoviv. the fact that his code didn't use that was confusing. in fact
  >> it is odd what he is doing there. why do $ptr = $ptr->{$node}; ? it just
  >> gets the new anon hash into $ptr. i can't make head nor tail of what he
  >> is trying to do in that loop.

  CW> It's basically just like a pointer in a C-style tree. At first
  CW> it points to the root node, then with each iteration a child node
  CW> gets added (if not already there) and the pointer is moved to point to
  CW> this child. The fact that it uses the name of a hash key instead of
  CW> a C struct member's name is just a variation of the concept.

i know that concept well. why he needed to assign {} is the
question. you can use autoviv to build that sort of thing.

  >> i was making that same point in a recent thread on autoviv and i know it
  >> well. the code is just too odd looking anyhow. as i keep telling him,
  >> use a templater.

  CW> I'm not convinced that a template system is the only answer to
  CW> the problem. A CSV module and Hash::Merge would be enough to populate
  CW> the hash structure, and one of the numerous xml modules should be
  CW> able to output what he wants - though that could be done in a few
  CW> lines of code as well. In fact, it should be nothing more than

  CW> dump_hash(\%hash);

  CW> sub dump_hash
  CW> {
  CW>   my($h, $ind) = @_;
  CW>   my $indent = "  " x $ind;
  CW>   return (ref $h eq "HASH") ?
  CW>     join('', map {
  CW>       $indent . "<$_>" . $/ .
  CW>       dump_hash($h->{$_}, $ind + 1) .
  CW>       $indent . "</$_>" . $/
  CW>     } keys %$h)
  CW>     :
  CW>     $indent . $h . $/;
  CW> }

  CW> I myself would, of course, use appropriate modules for production
  CW> code which check for corner cases and provide sensible error messages,
  CW> but the OPs problem and the possible solutions do make for a fine
  CW> academic task to learn about (or toy around with) topics like hashes,
  CW> references, recursion, top-down vs. bottom-up concepts or variable
  CW> depth algorithms.

a templater would be easier to see the xml layout (and xslt is just a
super fancy templater of sorts). but the code he used to descend the
tree was horrible in all sorts of ways.

and your code doesn't handle arrays which his data has. Template::Simple
can do all that with almost no effort.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Wed, 30 Mar 2011 07:02:28 -0700 (PDT)
From: Rob <rdw204@gmail.com>
Subject: Re: Search script to index dynamic pages
Message-Id: <11bf03b0-323d-4082-9e41-29d7e46844c2@w21g2000yqm.googlegroups.com>

Thank you all for your responses.

I have tried to download and index the pages using the script with the
LWP module, but so far without success. I have done quite a lot of
Perl programming in the past, but the LWP module is quite new to me.

I have written a test routine just to see if it works but this has not
worked either (below):

######################################
#!/usr/bin/perl -w
use strict;
use LWP::Simple;

$data =3D get("http://www.samlpesite.org");

print $data;
######################################

I just get server errors. The file permissions are correct and the LWP
module is installed on the server. Have I missed something obvious, or
used the 'get' routine incorrectly?

Any help would be great.

Regards

Rob

On Mar 29, 3:14=A0pm, J rgen Exner <jurge...@hotmail.com> wrote:
> Rob <rdw...@gmail.com> wrote:
> >As the majority of the content on the website is dynamic content, does
> >anybody know of any search CGI scripts that will index pages with
> >dynamic CGI content? (e.g. "website.com/cgi-bin/viewpage.cgi?id=3D100" )
>
> How would that script know which parameters are supported? Is id=3D100
> legal? Is id=3D100000000000000 legal? Is it myid=3D... instead of id=3D..=
 .?
>
> >If such a script is not available, is there a way to return content
> >from a dynamic page to a CGI script (for indexing purposes)?
>
> That is trivial, see
> =A0 =A0 =A0 =A0 perldoc -q "How do I fetch an HTML file?"
>
> jue



------------------------------

Date: Wed, 30 Mar 2011 10:53:09 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Search script to index dynamic pages
Message-Id: <slrnip6k5u.sai.tadmc@tadbox.sbcglobal.net>


[ Please do not top-post! ]


Rob <rdw204@gmail.com> wrote:


> #!/usr/bin/perl -w
> use strict;
  ^^^^^^^^^^


Here you make a promise to perl that you will declare all of
your variables before you use them.

perl is to refuse to run if you break the promise that you have
made to it.


> use LWP::Simple;
>
> $data = get("http://www.samlpesite.org");


Here you make use of a variable without declaring it first, 
so perl refuses to run your program, just like it is supposed to do.


> I just get server errors. 


Did it occur to you that the text of the error messages
might be helpful in debugging the problem?


> Have I missed something obvious,


Yes.

You have missed checking the server's error log when you got a server
error!


> Any help would be great.


Get your program to work *from the command line* first.

After it is working from the command line, *then* run it under
a web server.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


------------------------------

Date: Wed, 30 Mar 2011 06:30:21 -0700 (PDT)
From: "Rahul!!" <rahul_vasishta@yahoo.co.in>
Subject: strange behaviour w.r.t get function
Message-Id: <c358f27e-5bcc-4423-aca4-efd6864d01a5@f15g2000pro.googlegroups.com>

Please take a look at this code snippet,

my $query = "SELECT itemid from items";

my $sh = $dz_dbh->prepare( $query );

$sh->execute || return( $dz_dbh->errstr );
while(my @row=$sh->fetchrow()) {
    push (@item_id_arr,$row[0]);
}


foreach my $itemid (@item_id_arr){
    print $itemid;

    #statement 1
    my $string="http://mymachine/mywebsite/show_item.cgi?id=$itemid";

    #statement 2
    my $content = get($string) || print "Unable to get page for $itemid
\n";

}

Strangely all itemids are displayed on the console as 111111111. If I
comment statement 1 and statement 2 itemids are displayed
correctly .Strangely something is wrong in this loop. Is it because of
the get() function called. Looks really weird ...

Can somebody help on this,
Thanks,
-Rahul


------------------------------

Date: Wed, 30 Mar 2011 10:58:01 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: strange behaviour w.r.t get function
Message-Id: <slrnip6kf3.sai.tadmc@tadbox.sbcglobal.net>

Rahul!! <rahul_vasishta@yahoo.co.in> wrote:

>     my $content = get($string) || print "Unable to get page for $itemid
> \n";


This parses as:

    my $content = (get($string) || print "Unable to get page for $itemid\n");

So, $content will either be the return value from get() or the
return value from print().


> Strangely all itemids are displayed on the console as 111111111. 


print() returns a 1 when it succeeds...


> Can somebody help on this,


Use the lower-precedence form (or) rather than the high-precedence one (||).

    my $content = get($string) or print "Unable to get page for $itemid\n";


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


------------------------------

Date: Wed, 30 Mar 2011 09:22:56 -0700 (PDT)
From: "Rahul!!" <rahul_vasishta@yahoo.co.in>
Subject: Re: strange behaviour w.r.t get function
Message-Id: <54ebcb91-b668-4429-8360-484db8ab22b3@l14g2000pre.googlegroups.com>

On Mar 30, 8:58=A0pm, Tad McClellan <ta...@seesig.invalid> wrote:
> Rahul!! <rahul_vasis...@yahoo.co.in> wrote:
> > =A0 =A0 my $content =3D get($string) || print "Unable to get page for $=
itemid
> > \n";
>
> This parses as:
>
> =A0 =A0 my $content =3D (get($string) || print "Unable to get page for $i=
temid\n");
>
> So, $content will either be the return value from get() or the
> return value from print().
>
> > Strangely all itemids are displayed on the console as 111111111.
>
> print() returns a 1 when it succeeds...
>
> > Can somebody help on this,
>
> Use the lower-precedence form (or) rather than the high-precedence one (|=
|).
>
> =A0 =A0 my $content =3D get($string) or print "Unable to get page for $it=
emid\n";
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
> The above message is a Usenet post.
> I don't recall having given anyone permission to use it on a Web site.
>>>>>>>>>>>>>
print $itemid;
>>>>>>>>>>>>>
Actually the above print statement is printing all 1111111s instead of
item ids. Not sure but statement 1 and statement 2 are affecting the
value of $itemids.
If I comment the statement 1 and 2, its printing the correct value :(

print $itemid


------------------------------

Date: Wed, 30 Mar 2011 17:00:25 +0000 (UTC)
From: Willem <willem@toad.stack.nl>
Subject: Re: strange behaviour w.r.t get function
Message-Id: <slrnip6od9.1p2s.willem@toad.stack.nl>

Rahul!! wrote:
)>>>>>>>>>>>>>
) print $itemid;
)>>>>>>>>>>>>>
) Actually the above print statement is printing all 1111111s instead of
) item ids. Not sure but statement 1 and statement 2 are affecting the
) value of $itemids.
) If I comment the statement 1 and 2, its printing the correct value :(
)
) print $itemid

Copy and paste the actual code you're using.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 3339
***************************************


home help back first fref pref prev next nref lref last post