[21789] in Perl-Users-Digest
Perl-Users Digest, Issue: 3993 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 18 11:06:48 2002
Date: Fri, 18 Oct 2002 08:05:12 -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 Oct 2002 Volume: 10 Number: 3993
Today's topics:
Re: anonymous scalar refs are read-only -- can someone <usenet@tinita.de>
binaries as MySQL BLOBS via CGI (Steve)
Re: Controlling recursion depth with File::Find <bik.mido@tiscalinet.it>
Re: expanding variables in text strings (Helgi Briem)
Re: expanding variables in text strings <alecler@sympatico.ca>
Re: expanding variables in text strings (Helgi Briem)
Re: expanding variables in text strings <jeff@vpservices.com>
Re: expanding variables in text strings (Helgi Briem)
Re: Help Reading data in text files <kashmirnospam@bellnet.ca>
how to change compiler in Perl config? (Shambo)
Re: newbie question ... <Graham.T.Wood@oracle.com>
Re: newbie question ... <patrick@-/abazar\-.nl>
Re: newbie question ... (Tad McClellan)
Re: newbie question ... <Graham.T.Wood@oracle.com>
Re: newbie question ... <Graham.T.Wood@oracle.com>
Re: Passing array in the middle of the parrameter list <mjcarman@mchsi.com>
Re: Passing array in the middle of the parrameter list <Tassilo.Parseval@post.rwth-aachen.de>
Problem with file Sorting with Perl (raj shank)
Re: Python-style unit tests <ubl@schaffhausen.de>
Re: REGEXP probolem <Graham.T.Wood@oracle.com>
Sockets through a proxy/firewall (Nigel)
Substituting the first N matches <mfg@ee.ed.ac.uk>
Re: Substituting the first N matches (Tad McClellan)
Re: Substituting the first N matches (Helgi Briem)
Re: Switching from Python to Perl (Randal L. Schwartz)
Re: using regexp to add spaces (Cosmic Cruizer)
Re: using regexp to add spaces (Cosmic Cruizer)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 18 Oct 2002 10:54:35 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: anonymous scalar refs are read-only -- can someone explain why?
Message-Id: <aoop9b$odprk$1@fu-berlin.de>
Dan M <boss@moraldecay.com> wrote:
> Can someone explain to me why anonymous scalar refs are read-only when
> anonymous array and hash refrences are read-write? I have a pretty
> good idea thats it has to do with memory allocation, however I was
> hoping someone had a more indepth explanation that will put my curious
> mind to rest =)
> Example:
> my $hash_ref = { one => 2 };
> %$hash_ref = (changed => 1);
this is like doing:
%{{ one => 2 }} = (changed => 1);
(of course this statement is useless)
> my $array_ref = [3,4];
> @$array_ref = qw(this works);
@{[3,4]} = qw(this works);
> my $craptastic = '';
> my $scalar_ref_1 = \$craptastic;
> $$scalar_ref_1 = 'woot, I can change this';
this is like:
$craptastic = 'woot, I can change this';
> my $scalar_ref_2 = \'';
> $$scalar_ref_2 = 'this is read only??'; # 'Modification of a
> read-only value attempted' occurs at run time.
this is like:
'' = 'this is read only??';
hope this helps.
for further infomation, read perldoc perlref
tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/ \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: 18 Oct 2002 07:50:33 -0700
From: ineverlookatthis@yahoo.com (Steve)
Subject: binaries as MySQL BLOBS via CGI
Message-Id: <f0d57f86.0210180650.45752797@posting.google.com>
Dear folks,
I have a problem/concern with a perl script which is storing files
(word docs, pdf's, exe's, xls etc) as blobs in a MySQL databse. I am
not sure whether the issue is perl or CGI related so please excuse the
double post.
This is what I am doing.
# from upload form via CGI.pm
undef $/; # enable "slurp" mode
my $fh = $q->upload('uploaded_file');
# the file handle
my $fn = $q->param('uploaded_file');
# its name on the host
if ($fh){ binmode $fh;
# developed on a win system to run on linux
$doc = <$fh>};
Is this safe ? am I missing something ?
Having got my file into a scalar I store it in a MySQL blob simply by
calling INSERT and setting field = $doc via a placeholder.
Then to output the file to a user's browser I am doing this
$mysqlquery = qq[SELECT source, document
FROM docs
WHERE id= ? ];
$sth=$dbh->prepare (qq[$mysqlquery]);
$count=$sth->execute($myparams{'docseek'});
$hashrefs = $sth->fetchrow_hashref();
# some other stuff to get the original name back - works OK
print $q->header(-type=>'application/octet-stream',
-expires=>'-1d',
-attachment=>"$oldname");
# -attachment seems to be ignored by browsers I have used.
# I am using the trick of calling this via
"/cgi-bin/thisscript.cgi/$oldname"
# which seems to correctly name the recovered file.
print $hashrefs->{document}; # should I buffer this ????
That's it.
The issues are that it seemed to work via localhost on a win XP system
but on a linux system it behaves strangely. It seems to handle MS word
docs and PDF's OK but somehow corrupts .XLS files such that excel
won't open them. I worry that I am doing something unsafe here but I
don't know what
Any insights/suggestions appreciated.
Thanks
Steve
------------------------------
Date: Fri, 18 Oct 2002 16:39:15 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Controlling recursion depth with File::Find
Message-Id: <djdvqu833nod88m6897p0l5fd78tsj2vs2@4ax.com>
On Fri, 18 Oct 2002 00:20:43 -0400, Benjamin Goldberg
<goldbb2@earthlink.net> wrote:
>Michele Dondi wrote:
>>
>> Is there any easy/preferred way to impose limits to recursion depth
>> for File::Find::find, as for the -mindepth, -maxdepth parameteres of
>> the find command?
>>
>> Have I to count the number of directory separators?
>
>my $path = "/some/directory/path/";
>my $len;
>find sub {
> my $depth = substr( $_, $len ) =~ tr!/!!;
> return $File::Find::prune = 1 if $depth > $n;
> # do rest of processing here.
>}, $path;
Wow! I can even understand the way it works, and surprisingly that's
more or less what I had thought of.
Of course the above code would need some enhancements to take into
account the numer of slashes in $path and further complications arise
if multiple paths are supplied.
For ease of use File::Find could just include a $File::Find::depth var
with the obvious meaning. It should be set to 0 at root dirs and
incremented when recursing into a subdirectory and decremented when
getting back to the parent directory.
Also (my humble suggestion) the value of such an hypothetical var
could be assigned locally to the $. var so to be able to use a
statement like
print if 1 .. 3;
Michele
--
Liberta' va cercando, ch'e' si' cara,
Come sa chi per lei vita rifiuta.
[Dante Alighieri, Purg. I, 71-72]
I am my own country - United States Confederate of Me!
[Pennywise, "My own country"]
------------------------------
Date: Fri, 18 Oct 2002 11:28:45 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: expanding variables in text strings
Message-Id: <3daff03b.202537082@news.cis.dfn.de>
On Fri, 18 Oct 2002 10:01:10 +0000 (UTC), Bernard El-Hagin
<bernard.el-hagin@DODGE_THISlido-tech.net> wrote:
>> "I want to open a file, but I can't use open. I have to use
>> close instead."
>&close (*IN, 'filename');
>while (<IN>) {
> print;
>}
>sub close {
> my ($fh, $file) = @_;
> open ($fh, $file);
>}
>-------------------------
Bernard, you cheating S O B. ;-)
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Fri, 18 Oct 2002 09:28:44 -0400
From: Andre <alecler@sympatico.ca>
Subject: Re: expanding variables in text strings
Message-Id: <alecler-95B8DA.09284418102002@news1.qc.sympatico.ca>
In article <3dafd54c.195641918@news.cis.dfn.de>, helgi@decode.is wrote:
> On Fri, 18 Oct 2002 02:45:36 GMT,
> jason@generationterrorists.com (Jason Quek) wrote:
>
> >>If you use double quotes, the variables will be interpolated as
> >>you assign to $string.
>
> >Thank you for your post. Unfortunately, I need to use single quote
> >marks in this case.
>
> What?!? Why on earth would you have such a completely
> moronic, clueless requirement?
It makes sense if the problem is about replacing placeholders in a
template. Consider the text hardcoded with single quotes as an example of
text read from an outside source.
Andre
------------------------------
Date: Fri, 18 Oct 2002 14:00:53 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: expanding variables in text strings
Message-Id: <3db013f9.211688251@news.cis.dfn.de>
On Fri, 18 Oct 2002 09:28:44 -0400, Andre
<alecler@sympatico.ca> wrote:
>> What?!? Why on earth would you have such a completely
>> moronic, clueless requirement?
>
>It makes sense if the problem is about replacing placeholders in a
>template.
No, it doesn't.
>Consider the text hardcoded with single quotes as an example of
>text read from an outside source.
No, I won't.
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Fri, 18 Oct 2002 06:59:17 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: expanding variables in text strings
Message-Id: <3DB013B5.9040409@vpservices.com>
Bernard El-Hagin wrote:
> -------------------------
> &close (*IN, 'filename');
>
> while (<IN>) {
> print;
> }
>
> sub close {
> my ($fh, $file) = @_;
> open ($fh, $file);
> }
> -------------------------
Ah, at last Perl is mature enough to model the real world. Have you
thought of submitting that to CPAN? I suggest either under Politics::US
or perhpas somewhere in the Orwell::* hierarchy. The only fix I suggest
is to check the results of the close() and make sure to add "or live $!"
if your program can't proceed without the file.
--
Jeff
------------------------------
Date: Fri, 18 Oct 2002 14:36:19 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: expanding variables in text strings
Message-Id: <3db01b5a.213576917@news.cis.dfn.de>
On Fri, 18 Oct 2002 06:59:17 -0700, Jeff Zucker
<jeff@vpservices.com> wrote:
>Bernard El-Hagin wrote:
>
>> -------------------------
>> &close (*IN, 'filename');
>>
>> while (<IN>) {
>> print;
>> }
>>
>> sub close {
>> my ($fh, $file) = @_;
>> open ($fh, $file);
>> }
>> -------------------------
>
>
>Ah, at last Perl is mature enough to model the real world. Have you
>thought of submitting that to CPAN? I suggest either under Politics::US
>or perhpas somewhere in the Orwell::* hierarchy. The only fix I suggest
>is to check the results of the close() and make sure to add "or live $!"
> if your program can't proceed without the file.
&close (*IN,'filename') or &live($!);
while (<IN>) {
print;
}
sub close {
my ($fh, $file) = @_;
open ($fh, $file);
}
sub live {
my ($msg) = @_;
die $msg;
}
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Fri, 18 Oct 2002 10:17:48 -0400
From: "Kashmir" <kashmirnospam@bellnet.ca>
Subject: Re: Help Reading data in text files
Message-Id: <iKUr9.3285$OG5.351607@news20.bellglobal.com>
Thank you,
You guessed right. You got me started and I can see some results already.
Kahsmir
------------------------------
Date: 18 Oct 2002 08:01:17 -0700
From: shambo_p@yahoo.com (Shambo)
Subject: how to change compiler in Perl config?
Message-Id: <72190192.0210180701.5998729a@posting.google.com>
Perl is already installed on the Solaris 7 box here. I downloaded the
gcc compiler and need to tell Perl to use this compiler for makes. I
manually edited the Config.pm file and changed "cc" to "gcc", and gcc
is in my PATH, but certain modules are still tryting to call cc. Any
ideas?
most grateful,
Shambo
------------------------------
Date: Fri, 18 Oct 2002 11:49:57 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: newbie question ...
Message-Id: <3DAFE755.ADD5D1E8@oracle.com>
Patrick wrote:
> Hi,
>
> Is the following possible. I have a file with some lines like this:
>
> CA020007 blahblahblah 18,000 16,000
> CA020011 alsoblahdieblah 26,000 24,000
> CD115002 some text 27,000 26,000
> CD115003 again some text 22,000 22,000
>
> All tab-delimited.
>
> What I want to is:
> Search for CA, var search=CA, put the first collum into var1, second in
> var2 etc. until no more CA, skip to next search. If the next search (CD)
> is found, var search=CD, first collum in var1 etc.
>
> /Patrick.
What do you mean by first column?
When you find CA020007, is blahblahblah the first column or is 020007 the
first column? What will you do with the information after it has been put
into the columns?
This will put your data into a hash using the first 2 alphabetic characters
in the line as the key with the digits following the first 2 characters as a
secondary key and the 3 columns of data as values in an array below that.
This is something that is possible. Not sure if it is what you wanted.
perldoc perlvar will explain what a hash is. perldoc perldsc will explain
how nested hashes of hashes of arrays work and perldoc perlretut will
explain how regular expressions work.
Hope this helps
Graham Wood
open(FILE,"file") || die "Can't open file $!\n";
while(<FILE>){
# this regular expression is matching 2 Alphabetic characters, one or
more digits,
# a tab, one or more non-tab characters, a tab, one or more non-tab
characters, a tab , one or more non-tabs.
($key1,$key2,@values)= /([A-Z]{2})(\d+)\t([^\t]+)\t([^\t]+)\t([^\t]+)/;
$hash{$key1}{$key2}=[@values];
}
foreach $main (sort keys(%hash)){
print "MAIN: $main\n";
foreach $secondary (sort keys(%{$hash{$main}} ) ){
print "\tSECONDARY: $secondary\n";
foreach $value (@{$hash{$main}{$secondary}}){
print "\t\t$value\n";
}
}
}
------------------------------
Date: Fri, 18 Oct 2002 14:22:05 +0200
From: Patrick <patrick@-/abazar\-.nl>
Subject: Re: newbie question ...
Message-Id: <Pine.LNX.4.44.0210181418250.21763-100000@abazar.nl>
On Fri, 18 Oct 2002, Graham Wood wrote:
> Patrick wrote:
>
> > Hi,
> >
> > Is the following possible. I have a file with some lines like this:
> >
> > CA020007 blahblahblah 18,000 16,000
> > CA020011 alsoblahdieblah 26,000 24,000
> > CD115002 some text 27,000 26,000
> > CD115003 again some text 22,000 22,000
> >
> > All tab-delimited.
> >
> > What I want to is:
> > Search for CA, var search=CA, put the first collum into var1, second in
> > var2 etc. until no more CA, skip to next search. If the next search (CD)
> > is found, var search=CD, first collum in var1 etc.
> >
> > /Patrick.
>
> What do you mean by first column?
> When you find CA020007, is blahblahblah the first column or is 020007 the
> first column? What will you do with the information after it has been put
> into the columns?
>
> This will put your data into a hash using the first 2 alphabetic characters
> in the line as the key with the digits following the first 2 characters as a
> secondary key and the 3 columns of data as values in an array below that.
> This is something that is possible. Not sure if it is what you wanted.
>
> perldoc perlvar will explain what a hash is. perldoc perldsc will explain
> how nested hashes of hashes of arrays work and perldoc perlretut will
> explain how regular expressions work.
>
> Hope this helps
>
> Graham Wood
>
> open(FILE,"file") || die "Can't open file $!\n";
> while(<FILE>){
> # this regular expression is matching 2 Alphabetic characters, one or
> more digits,
> # a tab, one or more non-tab characters, a tab, one or more non-tab
> characters, a tab , one or more non-tabs.
> ($key1,$key2,@values)= /([A-Z]{2})(\d+)\t([^\t]+)\t([^\t]+)\t([^\t]+)/;
> $hash{$key1}{$key2}=[@values];
> }
>
> foreach $main (sort keys(%hash)){
> print "MAIN: $main\n";
> foreach $secondary (sort keys(%{$hash{$main}} ) ){
> print "\tSECONDARY: $secondary\n";
> foreach $value (@{$hash{$main}{$secondary}}){
> print "\t\t$value\n";
> }
> }
> }
>
>
Hi,
What I want is the following:
Search in the file to CA
First collum = CA020007
Second = blahblahblah etc ..
If CA is found
Print "CA Found:"
Print firstcollum (= CA020007), secondcollum etc
Until no more CA
Skip to next string.
/Patrick.
------------------------------
Date: Fri, 18 Oct 2002 08:14:57 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: newbie question ...
Message-Id: <slrnar02ah.2qu.tadmc@magna.augustmail.com>
Patrick <patrick@-/abazar\-.nl> wrote:
> Is the following possible.
I cannot understand what "the following" is asking for...
> I have a file with some lines like this:
>
> CA020007 blahblahblah 18,000 16,000
> All tab-delimited.
Those are not tab-delimited, or even tab-separated.
They appear to be separated by one or more space characters,
so I use that in my code below.
> What I want to is:
> Search for CA, var search=CA, put the first collum into var1, second in
> var2 etc.
This might help get you started towards whatever it is you
are trying to describe:
------------------------
#!/usr/bin/perl
use warnings;
use strict;
while ( <DATA> ) {
chomp;
my($search, $var1, $var2, $var3) = split / +/;
if ( /^CA/ ) {
print "processing 'CA': $search, $var1, $var2, $var3\n";
}
elsif ( /^CD/ ) {
print "processing 'CD': $search, $var1, $var2, $var3\n";
}
}
__DATA__
CA020007 blahblahblah 18,000 16,000
CA020011 alsoblahdieblah 26,000 24,000
CD115002 some text 27,000 26,000
CD115003 again some text 22,000 22,000
------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 18 Oct 2002 14:26:48 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: newbie question ...
Message-Id: <3DB00C18.B3B9901@oracle.com>
Patrick wrote:
> On Fri, 18 Oct 2002, Graham Wood wrote:
>
> > Patrick wrote:
> >
> > > Hi,
> > >
> > > Is the following possible. I have a file with some lines like this:
> > >
> > > CA020007 blahblahblah 18,000 16,000
> > > CA020011 alsoblahdieblah 26,000 24,000
> > > CD115002 some text 27,000 26,000
> > > CD115003 again some text 22,000 22,000
> > >
> > > All tab-delimited.
> > >
> > > What I want to is:
> > > Search for CA, var search=CA, put the first collum into var1, second in
> > > var2 etc. until no more CA, skip to next search. If the next search (CD)
> > > is found, var search=CD, first collum in var1 etc.
> > >
> > > /Patrick.
> >
> Hi,
>
> What I want is the following:
> Search in the file to CA
> First collum = CA020007
> Second = blahblahblah etc ..
>
> If CA is found
> Print "CA Found:"
> Print firstcollum (= CA020007), secondcollum etc
> Until no more CA
> Skip to next string.
>
> /Patrick.
open(FILE,"$file") || die "Can't open file $!\n";
@lines=<FILE>;
close FILE;
foreach $pattern (qw(CA CD)){ # add patterns as required
foreach(@lines){
if(/^$pattern/){
@parts=split(/\t/,$_);
print "$pattern Found:";
print "first column: $parts[0], second column: $parts[1], third column
$parts[2], fourth column $parts[3]\n";
}
}
}
The hash solution is more efficient as you only loop through the file lines once
rather than repeatedly but this is probably simpler to follow.
Graham
------------------------------
Date: Fri, 18 Oct 2002 14:31:09 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: newbie question ...
Message-Id: <3DB00D1C.AEA37559@oracle.com>
Graham Wood wrote:
> Patrick wrote:
>
> > On Fri, 18 Oct 2002, Graham Wood wrote:
> >
> > > Patrick wrote:
> > >
> > > > Hi,
> > > >
> > > > Is the following possible. I have a file with some lines like this:
> > > >
> > > > CA020007 blahblahblah 18,000 16,000
> > > > CA020011 alsoblahdieblah 26,000 24,000
> > > > CD115002 some text 27,000 26,000
> > > > CD115003 again some text 22,000 22,000
> > > >
> > > > All tab-delimited.
> > > >
> > > > What I want to is:
> > > > Search for CA, var search=CA, put the first collum into var1, second in
> > > > var2 etc. until no more CA, skip to next search. If the next search (CD)
> > > > is found, var search=CD, first collum in var1 etc.
> > > >
> > > > /Patrick.
> > >
> > Hi,
> >
> > What I want is the following:
> > Search in the file to CA
> > First collum = CA020007
> > Second = blahblahblah etc ..
> >
> > If CA is found
> > Print "CA Found:"
> > Print firstcollum (= CA020007), secondcollum etc
> > Until no more CA
> > Skip to next string.
> >
> > /Patrick.
>
> open(FILE,"$file") || die "Can't open file $!\n";
> @lines=<FILE>;
> close FILE;
>
> foreach $pattern (qw(CA CD)){ # add patterns as required
> foreach(@lines){
> if(/^$pattern/){
> @parts=split(/\t/,$_);
> print "$pattern Found:";
> print "first column: $parts[0], second column: $parts[1], third column
> $parts[2], fourth column $parts[3]\n";
> }
> }
> }
>
> The hash solution is more efficient as you only loop through the file lines once
> rather than repeatedly but this is probably simpler to follow.
>
> Graham
Doh! It obviously makes more sense to loop through file lines once and patterns
multiple times (like Tad's response does).
foreach(@lines){
foreach $pattern (qw(CA CD)){ # add patterns as required
if(/^$pattern/){
@parts=split(/\t/,$_);
print "$pattern Found:";
print "first column: $parts[0], second column: $parts[1], third column
$parts[2], fourth column $parts[3]\n";
}
}
}
------------------------------
Date: Fri, 18 Oct 2002 07:43:26 -0500
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: Passing array in the middle of the parrameter list
Message-Id: <aop076$6qg2@onews.collins.rockwell.com>
On 10/18/02 1:26 AM, Tassilo v. Parseval wrote:
>
> Also sprach Glodalec:
>>
>> Is there any way to pass an array as a parametter in the
>> middle of the parameter list ? [...]
>> Probably the only solution is to pass it as a reference
>
> Indeed. But you can hide that from the one using the subroutine by
> declaring a prototype:
>
> sub DoIt($$\@$) {
> #...
> }
> my @A = qw/a b c/;
> DoIt(1, 2, @A, 3);
>
> You have to pass an array, though:
>
> DoIt(1, 2, qw/a b c/, 3); # compile time error
Well, almost. It has to /look/ like an array.
DoIt(1, 2, @{[qw/a b c/]}, 3);
But that's probably more than the OP wanted to know...
-mjc
------------------------------
Date: 18 Oct 2002 14:03:55 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Passing array in the middle of the parrameter list
Message-Id: <aop4cb$e5d$2@nets3.rz.RWTH-Aachen.DE>
Also sprach Michael Carman:
> On 10/18/02 1:26 AM, Tassilo v. Parseval wrote:
>> sub DoIt($$\@$) {
>> #...
>> }
>> my @A = qw/a b c/;
>> DoIt(1, 2, @A, 3);
>>
>> You have to pass an array, though:
>>
>> DoIt(1, 2, qw/a b c/, 3); # compile time error
>
> Well, almost. It has to /look/ like an array.
>
> DoIt(1, 2, @{[qw/a b c/]}, 3);
>
> But that's probably more than the OP wanted to know...
The ref-trick, ok. That makes the cure worse than the desease. :-)
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: 18 Oct 2002 04:22:13 -0700
From: natarajshank@hotmail.com (raj shank)
Subject: Problem with file Sorting with Perl
Message-Id: <c54eb265.0210180322.6b34f70b@posting.google.com>
Hi,
I am having problem with sorting a flat file. I am reading the file
into an array and then I issue the array sort command like this
###########################################################
open (inF1, "$my_dir\\outFile1.txt") || die("Can not open file\n");
my $line2 = ""; my @outF1arr = ();
while ($line2 = <inF1>)
{
push(@outF1arr,$line2);
}#End while ($line2 = <inF1>)
### Sort by user_id
@outF1arr = sort(@outF1arr);
###########################################################
When it tries to sort the file, it throws out "Out of Memory" error.
The file I am trying to sort is 500 MB. I tried it on Windows NT and
Windows 2000 machines. Is this a limitation of Windows NT/2000 or
limitation of Perl interpreter or the sort command. The system I tried
had ample memory of 2Gig RAM. Is there a way of sorting the file with
out reading it into an array or is there a module from CPAN or others
which sorts file with out file size limits.
Thanks for your help.
Raj
------------------------------
Date: Fri, 18 Oct 2002 16:18:41 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Python-style unit tests
Message-Id: <aop8io$ijn$1@news.dtag.de>
Da Witch wrote:
> One benefit of this scheme is that it keeps the tests and the code
> that is being tested together. In contrast, the Perlish approach of
> putting the tests in a separate file
Perlish approach? It wouldnt be Perl if there wouldnt be MTOWTDI.
Check out Test::Inline if you want to keep your tests with your source code.
->malte
--
srand 108641088; print chr int rand 256 for qw<J A P H>
------------------------------
Date: Fri, 18 Oct 2002 14:35:49 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: REGEXP probolem
Message-Id: <3DB00E35.13F4E273@oracle.com>
Philip Lees wrote:
> On 18 Oct 2002 02:09:07 GMT, admin@hotmail.com (Mark Healey) wrote:
>
> >On Thu, 17 Oct 2002 23:51:45, ctcgag@hotmail.com wrote:
> >
> >> admin@hotmail.com (Mark Healey) wrote:
> >> > Why doesn't /reviews\.gif/ match "reviews.gif"?
> ^^
>
> > if (/reviews.gif/)
> ^
>
> Spot the difference?
>
> Phil
> --
> Ignore coming events if you wish to send me e-mail
Should still match "reviews.gif" though.
Graham
------------------------------
Date: 18 Oct 2002 06:37:04 -0700
From: nhcannings@hotmail.com (Nigel)
Subject: Sockets through a proxy/firewall
Message-Id: <361d2a80.0210180537.218396e3@posting.google.com>
I have two simple scripts for passing pdf documents from one machine
to another using sockets. These work perfectly well for most
machines, but from time to time I'm going to want to get them through
to a machine behind a corporate firewall. Assuming I know the IP
address of the firewall, and the local Ip address of the machine
itself, is there a simple way of modifying cli.pl (below) to pass the
documents through
thanks
Nigel
===========
(cli.pl)
use IO::Socket;
$remserv = 'xx.xx.xx.xx';
my $server = IO::Socket::INET->new(
PeerAddr => $remserv,
PeerPort => 5050,
Proto => 'tcp'
) or die "Can't create client socket: $!";
open FILE, "c:/perl/ReadMe.pdf";
binmode (FILE);
while (<FILE>) {
print $server $_;
}
close FILE;
(serv.pl)
use IO::Socket;
my $server = IO::Socket::INET->new(
Listen => 5,
LocalAddr => 'localhost',
LocalPort => 5050,
Proto => 'tcp'
) or die "Can't create server socket: $!";
my $client = $server->accept;
$fl="c:/perl/out1.pdf";
open FILE, ">$fl" or die "Can't open: $!";
binmode (FILE);
while (<$client>) {
print FILE $_;
}
close FILE;
------------------------------
Date: Fri, 18 Oct 2002 12:50:26 +0000 (UTC)
From: Michael F Gordon <mfg@ee.ed.ac.uk>
Subject: Substituting the first N matches
Message-Id: <aop02i$kr7$1@scotsman.ed.ac.uk>
Is is possible to replace a string a given number of times with one s///
while leaving the rest of the matches unchanged? For example, suppose
I have
text text FOO more text FOO and some more FOO almost done FOO end
Can I substitute just the first three instances of FOO and leave the
fourth and any others alone by doing something clever with a regular
expression and {3}, or do I have to use a loop and do a single
substitution each time round?
Michael Gordon
--
Quidquid latine dictum sit, altum viditur.
------------------------------
Date: Fri, 18 Oct 2002 08:11:19 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Substituting the first N matches
Message-Id: <slrnar023n.2qu.tadmc@magna.augustmail.com>
Michael F Gordon <mfg@ee.ed.ac.uk> wrote:
> Is is possible to replace a string a given number of times with one s///
> while leaving the rest of the matches unchanged?
Yes.
> Can I substitute just the first three instances of FOO and leave the
> fourth and any others alone by doing something clever with a regular
> expression and {3}, or do I have to use a loop and do a single
> substitution each time round?
s/// can do the "looping" for you at least:
my $cnt;
s/(FOO)/ $cnt++ < 3 ? 'BAR' : $1 /ge;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 18 Oct 2002 13:17:43 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Substituting the first N matches
Message-Id: <3db00998.209030700@news.cis.dfn.de>
On Fri, 18 Oct 2002 12:50:26 +0000 (UTC), Michael F Gordon
<mfg@ee.ed.ac.uk> wrote:
>Is is possible to replace a string a given number of times with one s///
>while leaving the rest of the matches unchanged? For example, suppose
>I have
>
> text text FOO more text FOO and some more FOO almost done FOO end
>
>Can I substitute just the first three instances of FOO and leave the
>fourth and any others alone by doing something clever with a regular
>expression and {3}, or do I have to use a loop and do a single
>substitution each time round?
This is not a particularly elegant method, but has the
decided advantages of at least working correctly and
being failrly transparent:
#!perl
use warnings;
use strict;
my $txt = 'text text FOO more text FOO and some more FOO
almost done FOO end';
print "$txt\n";
my $num = 0;
my $maxnum = 3;
while($num < $maxnum)
{
$num += $txt =~ s/FOO/BAR/;
}
print "$txt\n";
__END__
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: 18 Oct 2002 07:30:59 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Switching from Python to Perl
Message-Id: <868z0v95uk.fsf@red.stonehenge.com>
>>>>> "Benjamin" == Benjamin Goldberg <goldbb2@earthlink.net> writes:
Benjamin> Well, java's regex engine is supposed to be compatible with perl's, so
Benjamin> theoretically, one could make it so that calls to perl's regex engine
Benjamin> get translated to calls to Java's regex engine.
It can't be *completely* compatible. It can't have (?{...}) without
embedding an entire Perl interpreter into the Java engine. And that
hasn't happened (yet? :).
So PCRE is P*c*RE for some odd value of C.
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Fri, 18 Oct 2002 14:06:57 GMT
From: XcosmicX.XcruizerX@sbcglobal.com (Cosmic Cruizer)
Subject: Re: using regexp to add spaces
Message-Id: <Xns92AB485061D7Accruizermydejacom@64.164.98.6>
tadmc@augustmail.com (Tad McClellan) wrote in
<slrnaqv2m0.1n4.tadmc@magna.augustmail.com>:
<-- snip ->
>
>> and have the output say: g o o d m o r n i n g to you
>
>
> $str =~ s/(good\w*)/ join ' ', split m##, $1/ge;
>
>or
>
> $str =~ s/(good)/ my $x=$1; $x =~ s#(.)#$1 #g; $x /ge;
>
>
Thanks Tad. After looking at your code, this is what I finally did:
$str =~ s/(good[-a-z0-1]*\w*)/ join ' ', split m##, $1/ge;
It will handle the majority of what I see for this case... including items
such as "good-morning-2u"
Thanks
------------------------------
Date: Fri, 18 Oct 2002 14:24:15 GMT
From: XcosmicX.XcruizerX@sbcglobal.com (Cosmic Cruizer)
Subject: Re: using regexp to add spaces
Message-Id: <Xns92AB4B3FA9F5Dccruizermydejacom@64.164.98.6>
Michael Budash <mbudash@sonic.net> wrote in
<mbudash-52AD50.21353617102002@typhoon.sonic.net>:
<-- snip -->
>$str = 'goodmorning to you';
>$str =~ s|^(\w+)|join ' ', (split //, $1)|e;
>print "$str";
>
>yields:
>
>g o o d m o r n i n g to you
>
>note that using this code on 'good-morning to you' yields:
>
>g o o d-morning to you
>
>so you might actually want to use:
>
>$str =~ s|^(\S+)|join ' ', (split //, $1)|e;
>
>hth -
Thanks for the suggestion Michael. I don't think I posted a good example of
what I wanted to do, but you gave some excellent code I could follow and
modify (although I still remain dense in using "join"). The word I am
interested in changing can be in the middle of a sentence. I made a slight
change and came up with the following:
$str =~ s|(good[-a-z0-1]*\w*)|join ' ', (split //, $1)|e;
From here, I have also changed it to catch the keyword in the middle of the
string:
$str = "now good-morning-2u brown";
$str =~ s|([-a-z0-1]*morning[-a-z0-1]*\w*)|join ' ', (split //, $1)|e;
Thanks for your help.
------------------------------
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 3993
***************************************