[22642] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4863 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 18 18:06:23 2003

Date: Fri, 18 Apr 2003 15:05:07 -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           Fri, 18 Apr 2003     Volume: 10 Number: 4863

Today's topics:
        400 Bad Request with https proxy and LWP (Robert)
    Re: Accesing machines of a network <kasp@epatra.com>
    Re: changing the date <member17678@dbforums.com>
        How to use split function to split on a backslash <jboyan@qwest.net>
    Re: How to use split function to split on a backslash <tony_curtis32@yahoo.com>
    Re: How to use split function to split on a backslash <jboyan@qwest.net>
        HTML::Template question (Brent Middaugh)
    Re: HTML::Template question <noreply@gunnar.cc>
    Re: International Perl Beginners Mailing List <kasp@epatra.com>
    Re: Metadot Portal Server v5.5.2.1 (GPL) (Tad McClellan)
    Re: My 1st japh!! <bongie@gmx.net>
    Re: my cgi works but won't execute external commands su (Tad McClellan)
    Re: my cgi works but won't execute external commands su (Tad McClellan)
    Re: Need advice on my first Perl script <bob@aol.com>
    Re: regexp. for a two dates delimited with a minus <philip@zaynar.demon.co.uk>
        Returning Values from a Perl Thread (Douglas Garstang)
    Re: Returning Values from a Perl Thread <skuo@mtwhitney.nsc.com>
        Smart searching <kasp@epatra.com>
    Re: Still Stumped <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 18 Apr 2003 12:31:24 -0700
From: robert@nrc.net (Robert)
Subject: 400 Bad Request with https proxy and LWP
Message-Id: <22d0e990.0304181131.778a1f20@posting.google.com>

I've read many other posts and documents on the ways to connect to
https through a proxy, however with all the problems that I've seen
posted, I haven't seen a resolution to this. I'm trying to connect
through an http proxy to an https page. I can CONNECT but I can't GET
or POST. For some reason it won't connect no matter what I try, I get
this result:

Code: 400
Message: Bad Request
Request: HTTP::Request=HASH(0x82455a4)
Base: https://login.yahoo.com/config/login?3tuqsj3uiso3a
Error:400 Bad Request


Can anyone shed some light on what I would have to do for this to
work?
Is there anything out there that someone has already gotten to do
this?



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

#!/usr/bin/perl

use LWP::UserAgent;
use HTTP::Cookies; 
use LWP::Debug ('+');
use LWP::Protocol::https;
use Net::SSL;
use Net::SSLeay;
use URI::https;

$cookie = new HTTP::Cookies( ignore_discard => 1 );
$proxy = "http://200.162.XXX.XX:3128";
$browser= LWP::UserAgent->new(requests_redirectable => ['GET', 'HEAD',
'POST'],);
$browser->protocols_allowed(['http','https']);
$browser->proxy(['https', 'http'] => $proxy);
$browser->cookie_jar( $cookie );
$browser->agent('Mozilla/5.0 (compatible; MSIE 5.01; Windows 98)');
$request = new HTTP::Request('GET',
'https://login.yahoo.com/config/login?3tuqsj3uiso3a');
$response = $browser->request( $request );
if ($response->is_success){
	print "\nCode: ", $response->code, "\n";
	print "Message: ", $response->message, "\n";
	print "Request: ", $response->request, "\n";
	print "Base: ", $response->base, "\n";
	print "As_string: ", $response->as_string, "\n";
}else{
	print " - Proxy failed $proxy_ip:$proxy_port\n";
	print "\nCode: ", $response->code, "\n";
	print "Message: ", $response->message, "\n";
	print "Request: ", $response->request, "\n";
	print "Base: ", $response->base, "\n";
	print  "Error:" . $response->status_line . "\n";
	print "As_string: ", $response->as_string, "\n";
}


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

Date: Sat, 19 Apr 2003 01:56:00 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Re: Accesing machines of a network
Message-Id: <b7pnhd$m2i$1@newsreader.mailgate.org>

Thanks for the extra help Bryan.

I am nearly completion of my task and will post my script to all those who
helped me, like yourself, and also the c.l.p.m group for review.

There are one or two things that I would like to be cleared out. So by
Monday, I should post the script for your review.

Thanks a lot.
Kasp
--
"Accept that some days you are the pigeon and some days the statue."
"A pat on the back is only a few inches from a kick in the butt." - Dilbert.




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

Date: Fri, 18 Apr 2003 18:26:59 +0000
From: Mario542 <member17678@dbforums.com>
Subject: Re: changing the date
Message-Id: <2782944.1050690419@dbforums.com>


Steffen,

I tried what you said and it worked fine, but How do I take the date
that was entered in the web form($second) and change it to the @date
value so it can be changed?

my(@date) = ($second);

my(@tomorrow) = Add_Delta_Days(@date, +1);

Thanks,
Mario

--
Posted via http://dbforums.com


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

Date: Fri, 18 Apr 2003 15:37:07 -0600
From: "Jim Boyan" <jboyan@qwest.net>
Subject: How to use split function to split on a backslash
Message-Id: <62_na.462$FC4.89951@news.uswest.net>

I am trying to split a string which contains a backslash.

I have tried:

@words = split '\', $string;
@words = split "\", $string;
@words = split "\\", $string;
@words = split '\\', $string;

nothing seems to work I get errors from "search pattern not terminated" to
"syntax error".

$string contains something like "domainName\userName"

and I would like to end up with:
$words[0] = "domainName"
$words[1] = "userName"

Any Ideas?

Thanks in advance.





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

Date: Fri, 18 Apr 2003 16:28:52 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: How to use split function to split on a backslash
Message-Id: <87smsf8pgr.fsf@limey.hpcc.uh.edu>

>> On Fri, 18 Apr 2003 15:37:07 -0600,
>> "Jim Boyan" <jboyan@qwest.net> said:

> I am trying to split a string which contains a
> backslash.  I have tried:

> @words = split '\', $string; @words = split "\",
> $string; @words = split "\\", $string; @words = split
> '\\', $string;

The first argument to split() is a regular expression.

> $string contains something like "domainName\userName"
> and I would like to end up with: $words[0] =
> "domainName" $words[1] = "userName"

    my $string = 'domainName\userName';

    my ($domain, $user) = split /\\/, $string;

hth
t


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

Date: Fri, 18 Apr 2003 15:45:48 -0600
From: "Jim Boyan" <jboyan@qwest.net>
Subject: Re: How to use split function to split on a backslash
Message-Id: <fa_na.467$FC4.90655@news.uswest.net>

Bingo!!

thanks a bunch...

"Tony Curtis" <tony_curtis32@yahoo.com> wrote in message
news:87smsf8pgr.fsf@limey.hpcc.uh.edu...
> >> On Fri, 18 Apr 2003 15:37:07 -0600,
> >> "Jim Boyan" <jboyan@qwest.net> said:
>
> > I am trying to split a string which contains a
> > backslash.  I have tried:
>
> > @words = split '\', $string; @words = split "\",
> > $string; @words = split "\\", $string; @words = split
> > '\\', $string;
>
> The first argument to split() is a regular expression.
>
> > $string contains something like "domainName\userName"
> > and I would like to end up with: $words[0] =
> > "domainName" $words[1] = "userName"
>
>     my $string = 'domainName\userName';
>
>     my ($domain, $user) = split /\\/, $string;
>
> hth
> t




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

Date: 18 Apr 2003 13:39:18 -0700
From: smiddaugh@telispire.com (Brent Middaugh)
Subject: HTML::Template question
Message-Id: <51d7db68.0304181239.52a15f57@posting.google.com>

I'm using v2.6 of HTML::Template and running Activestate on a Windows
NT server.

The bit of code pretaining to HTML::Template:
my $template = HTML::Template->new(filename => 'main.tmpl');

And the CGI error i receive:
HTML::Template->new() : Cannot open included file main.tmpl : file not
found. at c:/perl/site/lib/HTML/Template.pm line 1580
	HTML::Template::_init_template('HTML::Template=HASH(0x19527a0)')
called at c:/perl/site/lib/HTML/Template.pm line 1177
	HTML::Template::_init('HTML::Template=HASH(0x19527a0)') called at
c:/perl/site/lib/HTML/Template.pm line 1071
	HTML::Template::new('HTML::Template','filename','main.tmpl') called
at C:\inetpub\wwwroot\returns\cgi-bin\main.pl line 8

I've verifed that the file main.tmpl is in the same directory as the
script, so I'm not quite sure why that H::T can't find the file.

Any Suggestions would be greatly appreciated.


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

Date: Fri, 18 Apr 2003 22:46:28 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: HTML::Template question
Message-Id: <b7po76$3h2jf$1@ID-184292.news.dfncis.de>

Brent Middaugh wrote:
> The bit of code pretaining to HTML::Template:
> my $template = HTML::Template->new(filename => 'main.tmpl');
> 
> And the CGI error i receive:
> HTML::Template->new() : Cannot open included file main.tmpl : file not
> found. at c:/perl/site/lib/HTML/Template.pm line 1580

<snip>

> I've verifed that the file main.tmpl is in the same directory as the
> script, so I'm not quite sure why that H::T can't find the file.
> 
> Any Suggestions would be greatly appreciated.

State the full path to the file, and not just the file name.

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Sat, 19 Apr 2003 02:13:52 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Re: International Perl Beginners Mailing List
Message-Id: <b7po2h$mpj$1@newsreader.mailgate.org>

I think this newsgroup rocks.

If you are stuck in Perl and wanna get out quickly...come here!
Best answers by the best Perl people.

I think if you concentrate on making a great site, that should be just good
enough.
--
"Accept that some days you are the pigeon and some days the statue."
"A pat on the back is only a few inches from a kick in the butt." - Dilbert.




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

Date: Fri, 18 Apr 2003 15:09:31 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Metadot Portal Server v5.5.2.1 (GPL)
Message-Id: <slrnba0mrr.akm.tadmc@magna.augustmail.com>

Daniel Guermeur <daniel@metadot.com> wrote:

> availability
> of its open source 

[snip]

>  Metadot Corporation brings the low
> cost


So which one is it, no cost or low cost?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 18 Apr 2003 20:04:51 +0200
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: My 1st japh!!
Message-Id: <1507778.t02RhSuSPJ@nyoga.dubu.de>

Michele Dondi wrote:
> The
> real problem is that as I said I can't really understand the use of
> (un)pack(). I know the docs are quite detailed, but maybe a tutorial
> with more examples would be useful[*].

perlpacktut.pod is a part of Perl 5.8.0.  :-)

Ciao,
        Harald
-- 
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
"Public speaking is very easy."
                -- George W. Bush Jr.



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

Date: Fri, 18 Apr 2003 15:22:16 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: my cgi works but won't execute external commands such as 'system(mkdir fred)' or 'open (filefandle, ">myfile.txt")'
Message-Id: <slrnba0njo.akm.tadmc@magna.augustmail.com>

Jolly Joe Jim Bob <jollyjoejimbob@hotmail.com> wrote:

> below you will find a junk of my code that...


You said it bubba.


> my problem...
> - when executing my script at the command line everything works great, of
> course it doesn't collect any data.


Why not?

If you had used the CGI module, you could test it at the command line
and provide form values too.


> any suggestions to a solution or a good source of information.

> #!/usr/bin/perl
> require "get_form_data.pl";


If you expect people to volunteer to help you, then you should as
much as you can yourself *before* resorting to asking for their time.

Enable warnings.

Enable strictures.

Use the CGI module.

Check the return value from Perl functions.

Use native Perl functions when possible instead of resorting
to "shelling out" via system().

Write Perl code rather than sed code.


> my $JobNumber = $FORM{'JobNumber'};
> my $DocketNumber = $FORM{'DocketNumber'};


You don't need to copy all of those from one scalar variable to
another scalar variable.

You can use them from the hash directly.


> my $tempname1 = "$JobNumber-$DocketNumber-$Description";
> my $tempname2 = substr($tempname1,0,30);


You do not need the 1st temporary variable:

    my $tempname2 = substr("$JobNumber-$DocketNumber-$Description", 0, 30);

> system (mkdir "$myfolder");


You should use Perl's mkdir() function rather than shelling out.


> ########################################################################
> #
> # Parsing the Illustratore Template
> #
> ########################################################################
> 
> my $myBIGScript = "sed -e 's/Description_Data/$Description/g' -e
> 's/PartID_Data/$JobNumber-$DocketNumber/g' -e
> 's/Creation_Date_Data/Date/g' -e 's/Modification_Date_Data/Date/g' -e
> 's/Sales_Rep_Data/$SalesRepID/g' -e 's/Sales_Order_Data/$SalesOrder/g' -e
> 's/Fabric_Data/$ProductFabricType/g' -e 's/Ship_Date_Data/$Ship/g'
> '/gfx_data/Live/templates/mocktemplate' >
> '$myfolder/Mockup/$DocketNumber-Mockup'";


Do that with Perl:

    my $myBIGScript = "perl -pe 's/Description_Data/$Description/g; s/PartID_Data/$JobNumber-$DocketNumber/g ...


> system ($myBIGScript);


Or, even better, do it in your main Perl program rather than shelling
out to another perl process:

   open TEMPLATE, '/gfx_data/Live/templates/mocktemplate' or die ...
   open MOCKUP, ">$myfolder/Mockup/$DocketNumber-Mockup" or die ...
   while ( <TEMPLATE> ) {
      s/Description_Data/$Description/g;
      s/PartID_Data/$JobNumber-$DocketNumber/g;
      ...
      print MOCKUP;
   }
   close TEMPLATE;
   close MOCKUP;


> open (OUTPUTFILE1, ">$outputfile");


You should always, yes *always*, check the return value from open():

  open(OUTPUTFILE1, ">$outputfile") or die "could not open '$outputfile' $!";


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 18 Apr 2003 15:23:34 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: my cgi works but won't execute external commands such as 'system(mkdir fred)' or 'open (filefandle, ">myfile.txt")'
Message-Id: <slrnba0nm6.akm.tadmc@magna.augustmail.com>

Jolly Joe Jim Bob <jollyjoejimbob@hotmail.com> wrote:


> - when executing my script at the command line everything works great, of
> course it doesn't collect any data.
> - when i post to it via my webpage it does collect the data but does not
> exectue parts 2, 3, and 4


Then there is something about the different environments that is
causing the problem.

Are you the same user (login) in both cases?

Are you in the same working directory in both cases?

Get it working completely and correctly from the command line first.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 18 Apr 2003 19:30:24 GMT
From: Optional <bob@aol.com>
Subject: Re: Need advice on my first Perl script
Message-Id: <k5j0avo3r4ql2phpanac8ieallp3709rja@4ax.com>

I've heard a rumor that on 18 Apr 2003 06:49:58 -0700,
scott@doppelgangerdesign.com (Scott Spencer) wrote the following:

>Thank you both for the great advice. Im sorry I didnt read the posting
>guidelines... I will check the documentation that was reccomended and
>look into some more "beginner" oriented lists.
>
>thanks again! 
>
>Scott 
>
>tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnb9v2r2.96s.tadmc@magna.augustmail.com>...
>> Scott Spencer <scott@doppelgangerdesign.com> wrote:
>> 
>> > keep only every 5th or 6 th file deleting the ones in between. For
>> > instance, file001 will stay but file 002 thru 005 will be deleted. I
>> > know its bad form to delete the files 
>> 
>> 
>> I don't know that.
>> 
>> Why is it bad form to delete the files?
>> 
>> 
>> > but it was the first and only
>> > solution I found in my book. 
>> 
>> 
>> If it does not do what you _want_ to do, then it is not a 
>> "solution" at all...
>> 
>> 
>> > this is my first time ever
>> > coding Perl so... : )
>> 
>> 
>> ... so have you read the Posting Guidelines that are posted
>> here frequently?
>> 
>>    http://mail.augustmail.com/~tadmc/clpmisc.shtml
>> 
>> 
>> 
>> > opendir (BOOGER, "$path") || die "cannot open your request??? $!"; 
>>                    ^     ^
>> 
>> Those quotes do not do anything, so they should not be there.
>> 
>> It would be helpful if your diagnostic message actually said
>> what directory it tried to open:
>> 
>>    opendir(BOOGER, $path) or die "cannot open '$path'  $!";
>> 
>> 
>> > @thefiles = readdir(BOOGER); 		#read the directory contents into an
>> 
>> 
>> You know that @thefiles might contain things that are NOT files, right?
>> 
>> Like directories, symlinks, etc...
>> 
>> If you want only plain files, you can use grep and a filetest:
>> 
>>    @thefiles = grep -f "$path/$_", readdir(BOOGER);
>> 
>> and now that you are done with the directory handle, you
>> should free that resource:
>> 
>>    closedir BOOGER;
>> 
>> 
>> > #and the script itself which onloy seems to work
>> > when it is in the home #directory. I think thats cause I used the
>> > unlink function.
>> 
>> 
>> No, that is because you did not read the documentation for
>> the functions that you are using.
>> 
>> You should read the documentation for the functions that you use:
>> 
>>    perldoc -f readdir
>> 
>>        if you're planning to filetest the return values
>>        out of a "readdir", you'd better prepend the
>>        directory in question.  Otherwise, because we
>>        didn't "chdir" there, it would have been testing
>>        the wrong file.
>> 
>> It is looking for the files in the current directory, but they
>> are not in the current directory, they are in the directory
>> that you opendir()ed.
>> 
>> 
>> > while ($current_count ne $end_frame)  {
>>                         ^^
>> 
>> ne is for comparing _strings_.
>> 
>> If you want to compare numbers, you use != instead.
>> 
>> 
>> > 	$current_file = @thefiles [$current_count]; 
>> 
>> 
>> If you had enabled warnings it would have said something about
>> that line.
>> 
>> Ask for all the help you can get.
>> 
>> You should always enable warnings when developing Perl code!
>> 
>> 
>> >         $current_file_number = $current_file;
>> > 	$current_file_number =~ s/\D*//;  #regular expression to remove all
>> > #alpha characters before numbers
>> 
>> 
>> Your comment is misleading as it will remove the first run of non-digits
>> (not "all" non-digits) regardless of whether they appear before or
>> after digit characters.
>> 
>>    s/^\D+//;  # remove all non-digits from start of string
>> 
>> 
>> > # I need to figure out the regular expression to wipe the .tif
>> > extension as #well.
>> 
>>    s/\.tif$//;  # remove the .tif extension
>> 
>> 
>> > 	unlink ($current_file);
>> 
>> 
>> Just because you asked for the file to be deleted does not mean
>> you got what you asked for.
>> 
>> You should check the return value to see if you got what you asked for:
>> 
>>    unlink($current_file) or die "could not unlink '$current_file'  $!";
>> 
>> 
>> > 	print '\n';
>> 
>> 
>> I'll bet that does not do what you think it does...

Also, please don't top-post...

If you want to keep every 5th file, you can just test to see if name
contains 0.tif or 5.tif, if so, next, else unlink $file.  Like this:

[!UNTESTED!]

#/usr/bin/perl -w
use strict;
our ($file) = undef;

foreach $file (<*.tif>) {

if ($file =~ /0.tif/ || $file =~ /5.tif/) {
}

else {
    unlink $file or die "Can't delete the file named $file! $!\n";
}

}



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

Date: Fri, 18 Apr 2003 22:26:15 +0100
From: Philip Taylor <philip@zaynar.demon.co.uk>
Subject: Re: regexp. for a two dates delimited with a minus
Message-Id: <H0RfXAA31Go+EwDC@zaynar.demon.co.uk>

In article <3e9d29e1$0$49106$e4fe514c@news.xs4all.nl>, Fizgig <FizgigNO@
SPAMequanimityREMOVETHISTO.nl> writes
>Hi,
>
>I need a regexp for a string with this format
>
>DD.MM.YYYY-DD.MM.YYYY
>
>I have already a great working expression for a single date;
>
>(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[
>0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[
>2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00
>))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-
>9]|[2-9]\d)?\d{2})
>
>How can i get it working for two dates delimited with a minus?

If you don't mind the "highly experimental" (??{...}) feature, this
might work to match only valid dates, and is slightly more readable:

$_ = '01.02.2003-04.05.2004';
if (m~^(\d+)\.(\d+)\.(\d+)-(\d+)\.(\d+)\.(\d+)$(??{
  if ($1>0 and $1<=31 and $2>0 and 'etc') { # (replace with something 
                                            #  correct)
    ''; # so that the (??{...}) will always match
  } else {
    '.'; # something which should never match after the $
  }
})~) {
  # ...
}

where everything between the ~s is in a single regular expression. 

perlre says about (??{code})
  "The code is evaluated at run time, at the moment this subexpression
may match. The result of evaluation is considered as a regular
expression and matched as if it were inserted instead of this construct"

You can make it succeed or fail by returning something that always or
never matches, using standard Perl code to check the values (which is
much neater than a gigantic regular expression).

-- 
Philip Taylor
philip@zaynar.demon.co.uk


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

Date: 18 Apr 2003 12:07:18 -0700
From: doug@pobox.com (Douglas Garstang)
Subject: Returning Values from a Perl Thread
Message-Id: <10d46bdc.0304181107.7e49c062@posting.google.com>

Trying to return data from a perl thread. Can anyone tell me whats
wrong with the following code? The output is '4'. It seems like the
return array is being treated in a scalar context. This code matches
exactly (as best I can tell) the simple example in the perlthrtut
docs.

Thanks, Douglas.


#!/usr/local/bin/perl

use strict;
use threads;

sub go {
   my @d;
   push (@d,"A");
   push (@d,"B");
   push (@d,"C");
   push (@d,"D");
   return @d;
}

sub main {
   my (@data);
   my $t;
   $t = threads->new(\&go);
   @data = $t->join;
   print @data;

}

main();


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

Date: Fri, 18 Apr 2003 12:28:37 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: Returning Values from a Perl Thread
Message-Id: <Pine.GSO.4.21.0304181226590.19778-100000@mtwhitney.nsc.com>

On 18 Apr 2003, Douglas Garstang wrote:

> Trying to return data from a perl thread. Can anyone tell me whats
> wrong with the following code? The output is '4'. It seems like the
> return array is being treated in a scalar context. This code matches
> exactly (as best I can tell) the simple example in the perlthrtut
> docs.
> 
> Thanks, Douglas.
> 
> 
> #!/usr/local/bin/perl
> 
> use strict;
> use threads;
> 
> sub go {
>    my @d;
>    push (@d,"A");
>    push (@d,"B");
>    push (@d,"C");
>    push (@d,"D");
>    return @d;
> }
> 
> sub main {
>    my (@data);
>    my $t;
>    $t = threads->new(\&go);
>    @data = $t->join;
>    print @data;
> 
> }
> 
> main();
> 



return is sensitive to context (see perldoc -f return).

Note the difference in results:

#! /bin/perl
use strict;
use warnings;
use threads;

sub go {
    my @d = qw(A B C D);
    print wantarray? "ARRAY\n" : "OTHER\n";
    return @d;
}

my @data;
my ($t) = threads->new("go");
@data = $t->join;
print "@data\n";

my $t2 = threads->new("go");
@data = $t2->join;
print "@data\n";
    

-- 
Hope this helps,
Steven



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

Date: Sat, 19 Apr 2003 02:08:07 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Smart searching
Message-Id: <b7pnos$mcv$1@newsreader.mailgate.org>

I have a huge list of absolute path names of all files of my network stored
currently in a file. I plan to shift it to a DB later.

I intend to make a google-like interface (using CGI). The user can then type
in some of the words of a file. For eg. suppose he is looking for a MP3
called "Perl Rocks". Then I want some way of searching through the file
names I have collected and search for this combination.

By intelligent search I mean that the results displayed should first attempt
to show files having both the words common, followed by records having
atleast one of the search words.

So suppose user says "A B", then I search for strings having (*A*B* |
*B*A*).
Then I search just for A | B.

However, this method's performance will degrade quickly as the number of
words increases to "A B C", "A B C D"...and so on.

As the number of given search words increases, so does the complexity and I
guess, so does the time spent on searching.

Is there any module already available to do such searching? Or could you
suggest some way out.

Thanks.
--
"Accept that some days you are the pigeon and some days the statue."
"A pat on the back is only a few inches from a kick in the butt." - Dilbert.




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

Date: Fri, 18 Apr 2003 19:40:03 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Still Stumped
Message-Id: <3EA05489.5070409@rochester.rr.com>

pooba53 wrote:

 ...
> I've tried the following within the loop that generates the output below:
> 
> 
> @range = ($begin..$end);
> push ( @{$AllGenes{$gene}}, @range);


You are pushing an array onto an array.  You probably want to push an 
array reference onto the array.  Maybe like:

push ( @{$AllGenes{$gene}}, \@range);

I think that will generate the structure you want.  You will end up with 
a hash called %AllGenes, each value of which is an array reference, each 
element of which array is a reference to another array.  Example:

    use Data::Dumper;
    @r1=(2..7);
    @r2=(10..15);
    @r3=(7..17);
    push @{$hash{one}},\@r1;
    push @{$hash{one}},\@r2;
    push @{$hash{two}},\@r2;
    push @{$hash{two}},\@r3;
    print Dumper(\%hash);

Note:  If you don't like the funky stuff this does with @r2 in the above

example, make the push statements look like:

    push @{$hash{one}},[@r1];

instead.  That will push a reference to a copy of the array, rather a
reference to the array itself, onto your hash.  That could be an issue
if you build an array, push it, then modify it and push it again.  With
the \@array method, you will push references to the *same* array, which
would not be what you want.  When you got all done, you would find that
all your data was the same -- the last stuff you put into the array.


 ...


> -Dan
 ...


-- 
Bob Walton



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

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.  

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 V10 Issue 4863
***************************************


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