[31038] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2283 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 19 16:09:45 2009

Date: Thu, 19 Mar 2009 13:09:08 -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           Thu, 19 Mar 2009     Volume: 11 Number: 2283

Today's topics:
        A small problem I can't quite work out. <sjmarshy@gmail.com>
    Re: A small problem I can't quite work out. <tadmc@seesig.invalid>
    Re: A small problem I can't quite work out. <sjmarshy@gmail.com>
    Re: FAQ posts <darkon.tdo@gmail.com>
    Re: How can I keep LWP::UserAgent from adding the http- <spasticgoblin@gmail.com>
    Re: How can I keep LWP::UserAgent from adding the http- <ben@morrow.me.uk>
    Re: How do I determine within the program what page I'm <tadmc@seesig.invalid>
    Re: How do I determine within the program what page I'm <spasticgoblin@gmail.com>
    Re: How do I determine within the program what page I'm <spasticgoblin@gmail.com>
    Re: How do I determine within the program what page I'm <ben@morrow.me.uk>
        new CPAN modules on Thu Mar 19 2009 (Randal Schwartz)
    Re: Non-textual output <ryan.mccoskrie@gmail.com>
        smart matching question <michaelgang@gmail.com>
    Re: smart matching question <1usa@llenroc.ude.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 19 Mar 2009 11:25:02 -0700 (PDT)
From: sj <sjmarshy@gmail.com>
Subject: A small problem I can't quite work out.
Message-Id: <e59bbd33-7b00-42d8-87a2-d47dfa3b589c@d19g2000yqb.googlegroups.com>

I'm making a program just for the joy of it, really, but I'm getting a
bug I just can't work out. Basically, when I run it, I get the message
'uninitiated value $whatever in pattern match (m//) at C:\wherever
line whatever'.
The problem is, they are initiated...I can post the code if it would
make this easier, but all variables are declared with 'my' not
'local'...I've tried putting them in different places in the code,
within loops or all at the begining etc...it used to work :/ maybe I
should just start again!


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

Date: Thu, 19 Mar 2009 13:39:47 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: A small problem I can't quite work out.
Message-Id: <slrngs54bj.kib.tadmc@tadmc30.sbcglobal.net>

sj <sjmarshy@gmail.com> wrote:

> Subject: A small problem I can't quite work out.


Please put the subject of your article in the Subject of your article.

    Subject: Use of uninitialized value

or some such.


> I'm making a program just for the joy of it, really, but I'm getting a
> bug I just can't work out. Basically, when I run it, I get the message
> 'uninitiated value $whatever in pattern match (m//) at C:\wherever
> line whatever'.


Please post the *actual text* of messages rather than paraphrase them.

Have you seen the Posting Guidelines that are posted here frequently?


> The problem is, they are initiated...


The word is "uninitialized", not uninitiated.


> I can post the code if it would
> make this easier, 


It would not make it easier. 

It would make it *possible*.


> but all variables are declared with 'my' not


"declaring a variable" and "defining a variable" are separate
and distinct concepts.

my() has to do with declaring variables.

Your message has to do with defining variables.


> 'local'...I've tried putting them in different places in the code,
> within loops or all at the begining etc...it used to work :/ maybe I
> should just start again!


We cannot repair code that we cannot see...


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Thu, 19 Mar 2009 12:04:34 -0700 (PDT)
From: sj <sjmarshy@gmail.com>
Subject: Re: A small problem I can't quite work out.
Message-Id: <4564fd2b-e959-4878-a929-0fda10f11cf9@b16g2000yqb.googlegroups.com>

Sorry, I'm completely new to both programming and usenet, I'll attempt
to pick it up as fast as possible.
I *think* it's the 'special' and 'checkinput' subs that are having the
problems...

#use strict;
#use warnings;

my $checked2;
my $flag = 1;
my $flag2 = 1;

while ($flag) {
	print $flag;
	my $usec;
if ($flag == 1) {
	$usec = start();
} else {
	$usec = restart();
}
$flag = $flag + 1;

my $use = checkinput ($usec);

writechat ($use);

printchatall ();

if ($use =~ /exit\n/i) {
$flag = 0;
}
}

sub start {
	intro();
	my $in = input();
	$flag2 = 1;
	return $in;
}

sub restart {
	print "what would you like me to say?: \n";
	my $in2 = input();
	$flag2 = 1;
	return $in2;
}

sub input {
	my $input = <>;
	return $input;
}

sub helprint {
	open (HELP,"< help.txt") || die("can't find help file: $!");
	while (<HELP>) {
		print $_;
	}
	close HELP;
	return 0;
}

sub checkinput {
	while ($flag2 >= 1) {
		my $checked2;
		my $test2 = shift;
		my $checked;
		$checked = special($test2);
		unless ($checked =~ /\n/i || $checked =~ /help\n/i || $checked =~ /
clear\n/i || $checked =~ /""/ || $checked =~ /exit\n/i) {
			$flag2 = 0;
		}
		$flag2 = $flag2 + 1;
		if ($flag2 >= 2) {
			$checked2 = special($checked);
		}
	}
	return $checked2;
}
sub special {

	my $test = (shift);

	if ($test =~ /^help\n$/i) {
		helprint ();
		my $newans = input();
		return $newans;
	} elsif ($test =~ /^exit\n$/i) {
		$flag = 0;
		return 0;
	} elsif ($test =~ /^clear\n$/i) {
		open (CLEAR,"> chatthing.txt") || die("can't clear: $!");
		print CLEAR "";
		my $newans1 = input();
		return $newans1;
	}else {
		return $test;
	}
	return "/n"
}

sub intro {
	open (INTRO,"< intro.txt") || die("can't find the intro: $!");
	while (<INTRO>) {
		print $_;
	}
	close INTRO;
}

sub writechat {
	my $answer = shift;
	open (CHATW,">> chatthing.txt") || die("can't open datafile: $!");
	print CHATW $answer;
	close CHATW;
}

sub printchatall {
	open (CHATR,"< chatthing.txt") || die("can't read datafile: $!");
	while (<CHATR>) {
		print $_;
	}
	close CHATR;
}


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

Date: Thu, 19 Mar 2009 11:56:23 -0400
From: "darkon" <darkon.tdo@gmail.com>
Subject: Re: FAQ posts
Message-Id: <GsadnQ8_iKG69l_UnZ2dnUVZ_trinZ2d@supernews.com>

I wrote in message news:9aOdnVuU5-vOWyPUnZ2dnUVZ_oWWnZ2d@supernews.com...
>  In  get_files() you do a Swchartzian transform with a grep in the middle 
> of it:

BTW, apologies to Randal for the typo in his name.  Schwartzian.



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

Date: Wed, 18 Mar 2009 18:24:42 -0700 (PDT)
From: CronJob <spasticgoblin@gmail.com>
Subject: Re: How can I keep LWP::UserAgent from adding the http-equiv strings  from the Head section of the page?
Message-Id: <22ef1769-ee64-472a-a63a-1f0c6eef82f3@z8g2000prd.googlegroups.com>

On Mar 18, 5:17=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth CronJob <spasticgob...@gmail.com>:
>
> > How can I keep LWP::UserAgent from adding the http-equiv strings from
> > the Head section of the page? When I run the following program below,
> > the $headers variable contains three Content-Type: listings. One from
> > the actual http header and one from the meta tag in the web page.
>
> See the ->parse_head method of LWP::UserAgent.
>
> You might want to try reading the docs of the modules you are using.
>
> Ben

Yes I agree with you. Unfortunately for me, I find the form that is
used in the perl documentation to be abstruse. I learn by working with
example code, not by reading abstract discussions about how code is
that do not contain working examples. Hopefully it will come to me
over time. I had the same issue with man pages years ago, but now its
second nature. I appreciate your response and I will look through the
documentation carefully.


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

Date: Thu, 19 Mar 2009 02:25:30 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How can I keep LWP::UserAgent from adding the http-equiv strings  from the Head section of the page?
Message-Id: <q1n896-f1m2.ln1@osiris.mauzo.dyndns.org>


Quoth CronJob <spasticgoblin@gmail.com>:
> On Mar 18, 5:17 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> > Quoth CronJob <spasticgob...@gmail.com>:
> >
> > > How can I keep LWP::UserAgent from adding the http-equiv strings from
> > > the Head section of the page? When I run the following program below,
> > > the $headers variable contains three Content-Type: listings. One from
> > > the actual http header and one from the meta tag in the web page.
> >
> > See the ->parse_head method of LWP::UserAgent.
> >
> > You might want to try reading the docs of the modules you are using.
> 
> Yes I agree with you. Unfortunately for me, I find the form that is
> used in the perl documentation to be abstruse. I learn by working with
> example code, not by reading abstract discussions about how code is
> that do not contain working examples. Hopefully it will come to me
> over time. I had the same issue with man pages years ago, but now its
> second nature. I appreciate your response and I will look through the
> documentation carefully.

I suspect you're trying to read the docs too fast. Unless you're a good
deal cleverer than me, there's no way you can read e.g. perldoc
LWP::UserAgent in one go and take it all in. Instead, when you find
yourself with a problem like the one you had, you need to carefully go
through every method in the perldoc and see if one of them does what you
want. Once you get some practice you'll find that picking out the
relevent bit of documentation *once you've got a specific problem in
mind* becomes much easier.

Ben



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

Date: Wed, 18 Mar 2009 22:39:51 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: How do I determine within the program what page I'm on after  LWP::UserAgent follows a redirect?
Message-Id: <slrngs3fk7.558.tadmc@tadmc30.sbcglobal.net>

CronJob <spasticgoblin@gmail.com> wrote:
> On Mar 18, 5:01 pm, Tad J McClellan <ta...@seesig.invalid> wrote:

>> Adopt a consistent programming style.

> Thanks for taking the time to critique the program, but that isn't
> what I was asking for 


   In <u93dhkluz2.fsf@wcl-l.bham.ac.uk> nobull@mail.com wrote:

      This is a discussion group not a helpdesk.  You post something 
      we discuss it's implications.  If the discussion happens to 
      answer a question you've asked that's incidental.


> my question (which I notice that you didn't even attempt to answer).


The carelessness evident in the code predisposed me to not bother 
with an answer.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Wed, 18 Mar 2009 18:37:48 -0700 (PDT)
From: CronJob <spasticgoblin@gmail.com>
Subject: Re: How do I determine within the program what page I'm on after  LWP::UserAgent follows a redirect?
Message-Id: <ac343441-886e-4a9a-ab6f-ae0815d56977@x1g2000prh.googlegroups.com>

On Mar 18, 5:01=A0pm, Tad J McClellan <ta...@seesig.invalid> wrote:
> CronJob <spasticgob...@gmail.com> wrote:
> > sub makeRequest( ) {
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0^ ^
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0^ ^
>
> Do you know what those parenthesis mean?
>
> > =A0 =A0 ($method, $path) =3D @_;
>
> Oh. That makes my earlier question rhetorical...
>
> Your prototype says you take no args, but you take 2 args.
>
> You should not use global variables like that. Use properly
> scoped variables instead:
>
> =A0 =A0 sub makeRequest {
> =A0 =A0 =A0 =A0 my($method, $path) =3D @_;
>
> > =A0 =A0 my $ua =3D new LWP::UserAgent;
> > =A0 =A0 my $request =3D new HTTP::Request($method, $path);
> > =A0 =A0 my $response =3D $ua->request($request);
>
> You use spaces around operators. That is a good style.
>
> > =A0 =A0 my $body=3D$response->content;
> > =A0 =A0 my $code=3D$response->code;
> > =A0 =A0 my $desc=3DHTTP::Status::status_message($code);
> > =A0 =A0 my $headers=3D$response->headers_as_string;
>
> You do not use spaces around operators. That is an ungood style.
>
> > =A0 =A0 $body =3D =A0$response->error_as_HTML if ($response->is_error);
>
> Toggle the style back to using spaces around operators.
>
> > Thanks in advance for any insight.
>
> Adopt a consistent programming style.
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

Thanks for taking the time to critique the program, but that isn't
what I was asking for and the example was cobbled together from
several sources. So discussion of the style wasn't really relevant to
my question (which I notice that you didn't even attempt to answer). I
guess you were so intent on how the trees were trimmed that you didn't
notice that you were in an orchard. But thanks for the pointer anyway.
I'll dereference at leisure.



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

Date: Wed, 18 Mar 2009 18:39:08 -0700 (PDT)
From: CronJob <spasticgoblin@gmail.com>
Subject: Re: How do I determine within the program what page I'm on after  LWP::UserAgent follows a redirect?
Message-Id: <83b8bc6e-8c5b-4a33-af9b-e9f1638c4dc5@e1g2000pra.googlegroups.com>

On Mar 18, 5:15=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth CronJob <spasticgob...@gmail.com>:
>
> > How do I determine within the program what page I'm on after
> > LWP::UserAgent follows a redirect? Is there a way I can determine
> > whether redirects has occurred and if so how many redirects were
> > followed and what there urls were? (obviously I know what the first
> > one was)
>
> See the ->request and ->previous methods of HTTP::Response. ->request
> returns the actual request that got this response, so you can get url of
> this response with $reponse->request->uri .
>
> Ben

Most helpful. I appreciate your response. Thank you for taking the
time to respond.


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

Date: Thu, 19 Mar 2009 02:34:05 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How do I determine within the program what page I'm on after  LWP::UserAgent follows a redirect?
Message-Id: <thn896-f1m2.ln1@osiris.mauzo.dyndns.org>


Quoth CronJob <spasticgoblin@gmail.com>:
> On Mar 18, 5:01 pm, Tad J McClellan <ta...@seesig.invalid> wrote:
> >
> > Adopt a consistent programming style.
> 
> Thanks for taking the time to critique the program, but that isn't
> what I was asking for and the example was cobbled together from
> several sources. So discussion of the style wasn't really relevant to
> my question (which I notice that you didn't even attempt to answer). I
> guess you were so intent on how the trees were trimmed that you didn't
> notice that you were in an orchard. But thanks for the pointer anyway.
> I'll dereference at leisure.

Being rude to a regular who was trying to help you is not likely to win
you many friends here. This newsgroup is not a helpdesk: if you post
code, you must expect all manner of comments and critiques. If you don't
find a reply helpful, well, noone here is obliged to help you.

Taking examples and playing with them is a perfectly good way to learn,
but once you get to the point of writing code that's supposed to be
useful you should understand what you're doing well enough to write for
yourself. Otherwise you've no hope of understanding what you wrote when
you come back to it later, and little hope of fixing it when it doesn't
do what you expect.

Ben



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

Date: Thu, 19 Mar 2009 04:42:30 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Thu Mar 19 2009
Message-Id: <KGqL2u.uuv@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Algorithm-LSH-0.00001_00
http://search.cpan.org/~miki/Algorithm-LSH-0.00001_00/
perl implementation of Locality Sensitive Hashing 
----
Any-Moose-0.06
http://search.cpan.org/~flora/Any-Moose-0.06/
use Moose or Mouse modules 
----
App-Rsnapshot-1.999_00001
http://search.cpan.org/~dcantrell/App-Rsnapshot-1.999_00001/
----
Astroboy-1.06
http://search.cpan.org/~leocharre/Astroboy-1.06/
organize mp3 files by album and artist 
----
Async-Hooks-0.01
http://search.cpan.org/~melo/Async-Hooks-0.01/
Hook system with asynchronous capabilities 
----
Authen-Simple-IMAP-0.0.2
http://search.cpan.org/~dmartin/Authen-Simple-IMAP-0.0.2/
Simple IMAP and IMAPS authentication 
----
CGI-IDS-1.0113
http://search.cpan.org/~hinnerk/CGI-IDS-1.0113/
PerlIDS - Perl Website Intrusion Detection System (XSS, CSRF, SQLI, LFI etc.) 
----
Catalyst-Controller-DBIC-API-1.002000
http://search.cpan.org/~lsaunders/Catalyst-Controller-DBIC-API-1.002000/
----
Catalyst-Model-DBIDM-0.04
http://search.cpan.org/~cbouvi/Catalyst-Model-DBIDM-0.04/
DBIx::DataModel model class 
----
Catalyst-Plugin-Compress
http://search.cpan.org/~xinming/Catalyst-Plugin-Compress/
Compress response 
----
Catalyst-Plugin-ConfigLoader-MultiState-0.05
http://search.cpan.org/~syber/Catalyst-Plugin-ConfigLoader-MultiState-0.05/
Convenient and flexible config loader for Catalyst. 
----
Class-C3-Componentised-1.0004
http://search.cpan.org/~ash/Class-C3-Componentised-1.0004/
----
Class-MOP-0.78_01
http://search.cpan.org/~drolsky/Class-MOP-0.78_01/
A Meta Object Protocol for Perl 5 
----
Config-JFDI-0.05
http://search.cpan.org/~rkrimen/Config-JFDI-0.05/
Just * Do it: A Catalyst::Plugin::ConfigLoader-style layer over Config::Any 
----
Data-Localize-0.00005
http://search.cpan.org/~dmaki/Data-Localize-0.00005/
Alternate Data Localization API 
----
File-Trash-1.06
http://search.cpan.org/~leocharre/File-Trash-1.06/
safe file delete 
----
FlatFile-DataStore-0.06
http://search.cpan.org/~bbaxter/FlatFile-DataStore-0.06/
Perl module that implements a flat file data store. 
----
FlatFile-DataStore-0.07
http://search.cpan.org/~bbaxter/FlatFile-DataStore-0.07/
Perl module that implements a flat file data store. 
----
Geo-ReadGRIB-0.91
http://search.cpan.org/~frankcox/Geo-ReadGRIB-0.91/
Perl extension that gives read access to GRIB 1 "GRIdded Binary" format Weather data files. 
----
LEOCHARRE-CLI2-1.03
http://search.cpan.org/~leocharre/LEOCHARRE-CLI2-1.03/
quick cli addons 
----
LEOCHARRE-CLI2-1.04
http://search.cpan.org/~leocharre/LEOCHARRE-CLI2-1.04/
quick cli addons 
----
Math-Transform-List-1.001
http://search.cpan.org/~prbrenan/Math-Transform-List-1.001/
Generate specified transformations of a list. 
----
Module-Install-Any-Moose-0.00001
http://search.cpan.org/~dmaki/Module-Install-Any-Moose-0.00001/
Any::Moose Support For Module::Install 
----
Module-Util-1.06
http://search.cpan.org/~mattlaw/Module-Util-1.06/
Module name tools and transformations 
----
Module-Util-1.06-withoutworldwriteables
http://search.cpan.org/~mattlaw/Module-Util-1.06-withoutworldwriteables/
Module name tools and transformations 
----
MooseX-WithCache-0.00004
http://search.cpan.org/~dmaki/MooseX-WithCache-0.00004/
Easy Cache Access From Moose Objects 
----
Muldis-D-0.62.0
http://search.cpan.org/~duncand/Muldis-D-0.62.0/
Formal spec of Muldis D relational DBMS lang 
----
Net-OpenSSH-0.32
http://search.cpan.org/~salva/Net-OpenSSH-0.32/
Perl SSH client package implemented on top of OpenSSH 
----
Net-SFTP-Foreign-1.50
http://search.cpan.org/~salva/Net-SFTP-Foreign-1.50/
SSH File Transfer Protocol client 
----
Parse-BooleanLogic-0.09
http://search.cpan.org/~ruz/Parse-BooleanLogic-0.09/
parser of boolean expressions 
----
Pod-POM-0.21
http://search.cpan.org/~andrewf/Pod-POM-0.21/
POD Object Model 
----
RDF-Query-2.100
http://search.cpan.org/~gwilliams/RDF-Query-2.100/
An RDF query implementation of SPARQL/RDQL in Perl for use with RDF::Redland and RDF::Core. 
----
String-Similarity-Group-1.05
http://search.cpan.org/~leocharre/String-Similarity-Group-1.05/
take a list of strings and segregate by similarity 
----
Tie-FlatFile-Array-0.05_01
http://search.cpan.org/~mumiaw/Tie-FlatFile-Array-0.05_01/
Treat a flatfile database as an array of arrays. 
----
Tie-STDOUT-1.04
http://search.cpan.org/~dcantrell/Tie-STDOUT-1.04/
intercept writes to STDOUT and apply user-defined functions to them. 
----
TryCatch-Error-0.01
http://search.cpan.org/~pfig/TryCatch-Error-0.01/
A simple error base class. 
----
WWW-Shorten-PunyURL-0.02
http://search.cpan.org/~pfig/WWW-Shorten-PunyURL-0.02/
An interface to SAPO's URL shortening service 
----
XML-RelaxNG-Compact-PXB-0.14
http://search.cpan.org/~mpg/XML-RelaxNG-Compact-PXB-0.14/
create perl XML (RelaxNG Compact) data binding API 
----
YAML-Visitor-0.00001
http://search.cpan.org/~nishikawa/YAML-Visitor-0.00001/
Like visitor style traversal for yaml 
----
Zucchini-0.0.16
http://search.cpan.org/~chisel/Zucchini-0.0.16/
turn templates into static websites 
----
forks-0.32
http://search.cpan.org/~rybskej/forks-0.32/
drop-in replacement for Perl threads using fork() 


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


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

Date: Thu, 19 Mar 2009 14:54:25 +1300
From: Ryan McCoskrie <ryan.mccoskrie@gmail.com>
Subject: Re: Non-textual output
Message-Id: <gps8kc$v6$1@news.albasani.net>

sln@netherlands.com wrote:

> On Thu, 19 Mar 2009 11:36:31 +1300, Ryan McCoskrie
> <ryan.mccoskrie@gmail.com> wrote:
> 
>>I've used perl for odd jobs with I/O before
>>but it's always been plain text.
>>
>>How do I get integer 0 instead of integer 48
>>(ascii 0) into a file?
> 
> Sure you say that now, but what happens when you want (ascii -1) into a
> file?
make that an unsigned byte to be more correct.

-- 
Quote of the login: 
No matter where I go, the place is always called "here".



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

Date: Thu, 19 Mar 2009 06:53:31 -0700 (PDT)
From: david <michaelgang@gmail.com>
Subject: smart matching question
Message-Id: <54352360-1bee-41e9-913c-85723346545e@p20g2000yqi.googlegroups.com>

Here showed is a piece from debugger
there are three parts

1)
DB<10> x 'a' ~~('a','b')
0  ''

2)
   DB<11> x 'a' ~~['a','b']
0  1

3)
   DB<12> @a = ('a','b')

   DB<13> x 'a' ~~ @a
0  1

My question is: what is the difference between the first and the third
case.
I think i miss a bit the point what is the difference betwwen @a and
().

Can someone help me to understand ?

Thanks,
David


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

Date: Thu, 19 Mar 2009 15:16:14 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: smart matching question
Message-Id: <Xns9BD372A3A6A51asu1cornelledu@127.0.0.1>

david <michaelgang@gmail.com> wrote in news:54352360-1bee-41e9-913c-
85723346545e@p20g2000yqi.googlegroups.com:

> Here showed is a piece from debugger
> there are three parts
> 
> 1)
> DB<10> x 'a' ~~('a','b')
> 0  ''

Note that you should get a warning for useless use of constant in void 
context here.

What is happening is simple. ('a', 'b') on the RHS is not a list. It is 
'a' *comma* 'b'. Therefore, the value of ('a', 'b') is 'b'. 'b' does not 
match 'a'. The result is false.

See http://japhy.perlmonk.org/articles/pm/2000-02.html#1.3

Also:

C:\DOCUME~1\asu1\LOCALS~1\Temp> perl -MO=Deparse t.pl
Useless use of a constant in void context at t.pl line 8.
use warnings;
use strict 'refs';
BEGIN {
    $^H{'feature_say'} = q(1);
    $^H{'feature_state'} = q(1);
    $^H{'feature_switch'} = q(1);
}
say 'yes' if ('???', 'b') ~~ 'a';
t.pl syntax OK

Note the '???' where 'a' used to be. That indicates that the constant 
'a' has been optimized away.

> 3)
>    DB<12> @a = ('a','b')
> 
>    DB<13> x 'a' ~~ @a
> 0  1
> 
> My question is: what is the difference between the first and the third
> case.
> I think i miss a bit the point what is the difference betwwen @a and
> ().

If you look at perldoc perlsyn ('Smart matching in detail'):

    Array   Any       array contains string    grep $_ eq $b, @$a

I don't know where this is explicitly stated, but the arguments to ~~ 
are evaluated in scalar context. Arrays, hashes, code blocks etc are 
converted to references.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


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

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:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#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 2283
***************************************


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