[19782] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1977 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 22 06:05:28 2001

Date: Mon, 22 Oct 2001 03:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1003745108-v10-i1977@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 22 Oct 2001     Volume: 10 Number: 1977

Today's topics:
    Re: alarm and put a timeout on a perl program an its sh <perrot@NOSPAM.fluxus.net>
    Re: alarm and put a timeout on a perl program an its sh <please@no.spam>
    Re: Config data not as text file but as module code --  <comdog@panix.com>
    Re: Config data not as text file but as module code --  <bart.lateur@skynet.be>
    Re: extract file extention from file name <bernard.el-hagin@lido-tech.net>
    Re: File I/O (Mark Jason Dominus)
    Re: how to use a function as function'sparam? (Mark Jason Dominus)
        I can use some help... please ... <basv@ozemail.com.au>
    Re: LTRIM & RTRIM ? <ad2ndhand@yahoo.com>
    Re: LTRIM & RTRIM ? (Mark Jason Dominus)
    Re: LTRIM & RTRIM ? <Thomas@Baetzler.de>
    Re: LTRIM & RTRIM ? <ad2ndhand@yahoo.com>
    Re: LTRIM & RTRIM ? <jurgenex@hotmail.com>
    Re: LTRIM & RTRIM ? (Bernd Dulfer)
    Re: perl algorithm <chawig@eplus-online.de>
    Re: perl algorithm <goldbb2@earthlink.net>
    Re: perl algorithm (Rafael Garcia-Suarez)
    Re: perl algorithm <jurgenex@hotmail.com>
    Re: perl algorithm (Martien Verbruggen)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 22 Oct 2001 11:09:49 +0200
From: "Gildas PERROT" <perrot@NOSPAM.fluxus.net>
Subject: Re: alarm and put a timeout on a perl program an its shell childs ?
Message-Id: <9r0nvo$6sa$1@wanadoo.fr>

Thanks a lot Garry for your answer.
In fact, your were right on several points.

Now, I use a pipe to get execute the shell script but I still have the same
problem. Usually, with command like "ping host", when the timeout is
reached, the program below allows to kill the ping command. With my other
specific command, after timeout, the program exits but the command is still
present in the running processes.

use strict;

my $timeout = 3;
$SIG{ALRM} = sub { print "TIMEOUT\n"; die "\n"; };
#my $cmd = "/local/pck/gateway/test/fakesmsc -m 1 from to text salut";
my $cmd = "/bin/ping metaphore";

open(CMD, "$cmd |") or die "Can't execute \"$cmd\"\n";
eval {
        alarm($timeout);
        while (<CMD>) {
                print $_;
        }
        alarm(0);
};
close(CMD);
print "End of program\n";

Any idea why that command doesn't react as the ping command to the "die" ?

Thanks in advance for your help.        Gildas.

"Garry Williams" <garry@ifr.zvolve.net> a écrit dans le message news:
slrn9t3a7t.mts.garry@zfw.zvolve.net...
> On Fri, 19 Oct 2001 14:50:50 +0200, Gildas PERROT
> <perrot@NOSPAM.fluxus.net> wrote:
>
> > I want to put a timeout on a perl program and its shell child. In order
to
> > kill both of them, I use "exec" but in that cas, I can set the SIG{ALRM}
> > message which by default "Alarm clock". How can I do that ? When using
> > system or '' to execute the shell command, this one is not killed at the
> > timeout.
>
> Huh?  I don't understand most of that.
>
> > Here is my perl code :
> >
> > $timeout = 1;
> > $SIG{'ALRM'} = "TIMEOUT !";
>
> This is nonsense.
>
> See the perlvar manual page for how to correctly use the %SIG hash.
> The perlipc manual page also discusses "Signals".
>
> > alarm($timeout);
> > exec("/shell_cmd");
> > alarm(0);
>
> Huh?  The perlfunc manual page tells you that exec() does *not*
> return (assuming "/shell_cmd" *can* be exec()ed).  How do you suppose
> the last statement will ever be executed.
>
> Maybe the FAQ will help.  Read the "How do I timeout a slow event?"
> section of the perlfaq8 manual page.  It will refer you to the
> "Signals" section of the perlipc manual page.  That section discusses
> using alarm() for timing out stuff.
>
> You are enabling warnings and use strict, aren't you?
>
> Hope this helps.
>
> --
> Garry Williams




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

Date: Mon, 22 Oct 2001 09:34:05 GMT
From: Andrew Cady <please@no.spam>
Subject: Re: alarm and put a timeout on a perl program an its shell childs ?
Message-Id: <87g08c6mwy.fsf@homer.cghm>

"Gildas PERROT" <perrot@NOSPAM.fluxus.net> writes:

> $SIG{ALRM} = sub { print "TIMEOUT\n"; die "\n"; };

I didn't read the rest of your post so I can't help you with that, but
just FYI you can't put "print" in a signal handler.  Well, you can,
but you're liable to screw up your stdio buffers and crash perl, so
don't.  In this case, you shoul die "timeout", and have the code after
your eval print the message.


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

Date: Mon, 22 Oct 2001 03:48:22 -0400
From: brian d foy <comdog@panix.com>
Subject: Re: Config data not as text file but as module code -- Oops!
Message-Id: <comdog-3F9EFC.03482222102001@news.panix.com>

In article <9qs5uj$pm999$1@ID-101658.news.dfncis.de>, "Markus Dehmann" 
<markus.cl@gmx.de> wrote:

> "brian d foy" <comdog@panix.com> wrote in message
> news:comdog-0DE686.10495720102001@news.panix.com...
> 
> > > script with "use Data;" is killed by the system.
> >
> > what do you mean "killed by the system".  you'll need to speak in
> > something other than metaphors to help us help you. ;)
> 
> no, this isn't a metaphor! 

oh, my apologies.  somehow i parsed that as "killing the system"
rather than its obvious and literal meaning.  sorry for my
confusion. :(

-- 
brian d foy <comdog@panix.com> - Perl services for hire
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html



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

Date: Mon, 22 Oct 2001 09:51:11 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Config data not as text file but as module code -- Oops!
Message-Id: <qrq7ttgech44bidavrdcbjofql4j93fc0k@4ax.com>

Markus Dehmann wrote:

>> package Data;
>> ... Exporter...
>> %hash = ( key1=>[[1,2],[3,4],[4,5]], key2=>... );
>> 1;
>
>Oops, now I saw when my module Data.pm is about 20MB, it can't be used. My
>script with "use Data;" is killed by the system.
>
>Why this? It shouldn't be a problem for the interpreter to read 20 MB,
>right?

It needs a multiple of 20MB. First you're making a large list, and then
you're trying to populate a hash from this list.

You can try to split up the data:

	$hash{key1} = [[1,2],[3,4],[4,5]];
	$hash{key2} = ... ;


Personally, I'd look into turning this into a database, perhaps through
a tied hash.

-- 
	Bart.


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

Date: 22 Oct 2001 07:43:39 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: extract file extention from file name
Message-Id: <slrn9t7j3p.ec9.bernard.el-hagin@gdndev25.lido-tech>

On Fri, 19 Oct 2001 20:02:22 +0100, jimbo <jimbo@soundimages.co.uk> wrote:
> "peter" <peter_icaza@REMOVE2REPLYuhc.com> wrote
> 
>> long.file.name.1
> 
> You don't need a regex, if you don't want one.  How about this:
> 
>   my $name = '1.name.file.long';
> 
>   # I changed it because the single digit '1' looked lonely all by
>     itself printed later
> 
>   my $ext = [reverse split /\./, $name];
>   print $ext->[0] if scalar @$ext > 1;
> 
> produces the output
> 
>   long
> 
> So, there 'ya go.  Not all problems are regex problems.  This also
> prevents filenames which don't contain an extension from being printed.
> 
> Perl *isn't* just for regex's anymore.  Hey, maybe it never was?


Blah, blah, blah. And what the hell is /\./ if not a regex?


Cheers,
Bernard


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

Date: Mon, 22 Oct 2001 07:47:40 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: File I/O
Message-Id: <3bd3cf19.272e$383@news.op.net>

In article <slrn9t3j80.2cs.tadmc@tadmc26.august.net>,
Tad McClellan <tadmc@augustmail.com> wrote:
>Neal E. Coombes <Neal.Coombes@telus.net> wrote:
>Don't interleave reads and writes.
>
>If you do, then you need to seek() correctly between each:
>
>   perldoc -f seek

I don't think that is Neal's problem here.  The 'seek' is only
necessary if you want to be sure that the written data is flushed
before you try to read it back.  But Neal's complaint is that the
written data isn't written at all.

>If what you are putting in is not *exactly the same number of bytes*
>as what you are taking out, then even this approach won't work.

That sort of depends on what you mean by 'work'.

In any case, i don't think it's relevant here.
-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Mon, 22 Oct 2001 08:17:14 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: how to use a function as function'sparam?
Message-Id: <3bd3d60a.2888$328@news.op.net>

In article <20011019.215852.352118606.1207@localhost.localdomain>,
_Mario Latens <mario.lat@libero.it> wrote:
>I'd like tu use a function g(x)
>I'd like to pass this function to another function: f(g(x))
>how can I do that?

sub apply_twice {
  my ($func, $arg) = @_;
  $func->($func->($arg));
}

sub add_3 { $_[0] + 3 }

$n = apply_twice(\&add_3, 4);    # result $n is 10

$m = apply_twice(sub { $_[0] * 3 }, 2);   # result $m is 18


>Can you write a short and simple example?

Hope this helps.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Mon, 22 Oct 2001 16:26:19 +0800
From: "Bas Voordendag" <basv@ozemail.com.au>
Subject: I can use some help... please ...
Message-Id: <2LQA7.1886$G%4.134247@ozemail.com.au>

I am working on a shopping cart and I'll have this problem  that bugs me now
for days.

This is how it works;
The user has a uniek cart file : $mycookies{'sessionid'}.dat
It contains the shopping cart items, and I want to be able for the quantity
to be changeable.
The contents ir read and loaded into an array.
Then the original cart file is erased.
Then the formdata containing the new quantities need to be "mixed" with the
array containing the discription etc.
The "old" value: $content  needs to be replaced with the new value:
$myvalue;

Using the foreach does not seem to work this way, I get the right new values
but the discription is wrong.

I can use some help.......


The code:

# Open the cart file for input
if (!open (IN, "<user_carts\\$mycookies{'sessionid'}.dat")) {
print "<p>Error opening catalogue file</p>";
exit;
}
# Read the cart file into an array then close the file
@cart = <IN>;
close (IN);

# Erase cart file cart.dat
open (CART, ">user_carts\\$mycookies{'sessionid'}.dat");
flock (CART, 2);
seek (CART, 0, 2);
print CART "";
flock (CART, 8);
close CART;


#
============================================================================
=
# Process form data
foreach $pair (@form_data) {
($name, $myvalue) = split (/=/, $pair);
$form_data{$name} = $myvalue;
#
============================================================================
=


# Process each record
foreach $item (@cart) {
# Remove newline character from end of record
chop;
# Split out record fields
($field, $description, $unit, $price, $content, $row_total) = split (/:/,
$item);
}

# Allocate new value
$content = $myvalue;

# Calculate row total
$row_total = $content * $price;

# Output items to cart.dat file
# Update cart file cart.dat
open (CART, ">>user_carts\\$mycookies{'sessionid'}.dat");
flock (CART, 2);
seek (CART, 0, 2);
print CART "$field:$description:$unit:$price:$content:$row_total\n";
flock (CART, 8);
close CART;
}







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

Date: Mon, 22 Oct 2001 15:50:30 +0800
From: "ad2ndhand" <ad2ndhand@yahoo.com>
Subject: Re: LTRIM & RTRIM ?
Message-Id: <9r0i6q$qpo$1@coco.singnet.com.sg>

Maybe I wasn't too clear in my pervious post.

For eg, if I have string "  table is table  " (notice the double spaces at
the front and at the back), how do I trim it to become "table is table"
without altering the space existing between the words ? The 's' operator I
suppose will affect the spaces in between the words.


"Ron Reidy" <rereidy@indra.com> wrote in message
news:3BD3C509.B7FDE2F4@indra.com...
| ad2ndhand wrote:
| >
| > Anyway I can do left trim and right trim in Perl. The closest thing I
can
| > think of is chomp and chop but that only takes care the back part but
not
| > the front part.
| Look at regexes and the 's' operator.
| --
| Ron Reidy
| Oracle DBA
| Reidy Consulting, L.L.C.




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

Date: Mon, 22 Oct 2001 07:54:34 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: LTRIM & RTRIM ?
Message-Id: <3bd3d0b9.27db$2@news.op.net>

In article <9r0f39$qc9$1@coco.singnet.com.sg>,
ad2ndhand <ad2ndhand@yahoo.com> wrote:
>Anyway I can do left trim and right trim in Perl. 

sub ltrim {
  $_[0] =~ s/^\s+//;
}

sub rtrim {
  $_[0] =~ s/\s+$//;
}

sub trim {   # trim both 
  &ltrim; &rtrim;
}

Hope this helps.

Someone else in this thread suggested regexes.  You poo-poohed him.
But it was good advice. 

You shouldn't be so quick to dismiss advice you don't understand.  
If it doesn't seem clear how to use it, try asking for more information.
-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Mon, 22 Oct 2001 10:00:25 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: LTRIM & RTRIM ?
Message-Id: <47k7ttoc0kfngebb61i2u3ckpa60h7qrvs@4ax.com>

On Mon, 22 Oct 2001, "ad2ndhand" <ad2ndhand@yahoo.com> wrote:
>For eg, if I have string "  table is table  " (notice the double spaces at
>the front and at the back), how do I trim it to become "table is table"
>without altering the space existing between the words ? The 's' operator I
>suppose will affect the spaces in between the words.

Please don't use Jeopardy! style quoting:
http://www.geocities.com/nnqweb/nquote.html#Q7

my $string = "  table is table  ";

$string =~ s/^\s*(.*?)\s*$/$1/;

print $string;

This will remove leading and trailing whitespace characters like tabs,
spaces and newlines.

HTH,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: Mon, 22 Oct 2001 16:20:16 +0800
From: "ad2ndhand" <ad2ndhand@yahoo.com>
Subject: Re: LTRIM & RTRIM ?
Message-Id: <9r0jum$r2r$1@coco.singnet.com.sg>

Okie...thankz....I'm new here. I'll be more careful nxt time.

"Mark Jason Dominus" <mjd@plover.com> wrote in message
news:3bd3d0b9.27db$2@news.op.net...
| In article <9r0f39$qc9$1@coco.singnet.com.sg>,
| ad2ndhand <ad2ndhand@yahoo.com> wrote:
| >Anyway I can do left trim and right trim in Perl.
|
| sub ltrim {
|   $_[0] =~ s/^\s+//;
| }
|
| sub rtrim {
|   $_[0] =~ s/\s+$//;
| }
|
| sub trim {   # trim both
|   &ltrim; &rtrim;
| }
|
| Hope this helps.
|
| Someone else in this thread suggested regexes.  You poo-poohed him.
| But it was good advice.
|
| You shouldn't be so quick to dismiss advice you don't understand.
| If it doesn't seem clear how to use it, try asking for more information.
| --
| @P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub
p{
|
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^or
d
| ($p{$_})&6];$p{$_}=/
^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
| close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep
rand(2)if/\S/;print




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

Date: Mon, 22 Oct 2001 02:04:06 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: LTRIM & RTRIM ?
Message-Id: <3bd3e109@news.microsoft.com>

[Please don't post jeopardy style]
[Please trim the quote to the relevant part for your reply]

"ad2ndhand" <ad2ndhand@yahoo.com> wrote in message
news:9r0i6q$qpo$1@coco.singnet.com.sg...
> For eg, if I have string "  table is table  " (notice the double spaces at
> the front and at the back), how do I trim it to become "table is table"
> without altering the space existing between the words ? The 's' operator I
> suppose will affect the spaces in between the words.

Just anchor the REs to the beginning (^) and end ($) or the string.
Then spaces in the middle won't be altered.

jue




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

Date: 22 Oct 2001 02:13:09 -0700
From: bdulfer@bigmailbox.net (Bernd Dulfer)
Subject: Re: LTRIM & RTRIM ?
Message-Id: <1a5e9ec9.0110220113.7a276af4@posting.google.com>

> Anyway I can do left trim and right trim in Perl. The closest thing I can
> think of is chomp and chop but that only takes care the back part but not
> the front part.

Use a substitution with regular expression:
$var =~ s/^\s+(.*?)\s+$/$1/


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

Date: Mon, 22 Oct 2001 09:15:33 +0200
From: Martial Chateauvieux <chawig@eplus-online.de>
Subject: Re: perl algorithm
Message-Id: <3BD3C795.5040602@eplus-online.de>


while(defined($x = @file)){
	($blah, $blah2, $blah3, $blah4) = split "\t", $x;
	print $x unless exists $test{$blah, $blah2, $blah4};
	$test{$blah, $blah2, $blah4}++;
}

Have fun
Martial Chateauvieux

Ivan Kozik wrote:

> Hello-
> 
> I'm having trouble writing an algorithm in perl. 
> I have a tab delimited file that looks like this:
> 
> <snip>
> 100039  2129881 3e-28   100.000
> 100039  128401  3e-28   100.000
> 100039  587509  3e-28   100.000
> 100039  169084  3e-28   100.000
> 100039  7442093 2.2e-20 80.000
> 100039  2499217 2.2e-20 80.000
> 100039  1167892 2.2e-20 80.000
> 100039  3914100 1.7e-16 61.947
> 100039  22649   1.7e-16 61.947
> <snip>
> 2129881 100039  3e-30   100.000
> 2129881 2129881 3e-30   100.000
> 2129881 128401  3e-28   100.000
> 2129881 587509  3e-28   100.000
> 2129881 169084  3e-28   100.000
> 2129881 7442093 2.2e-20 80.000
> 2129881 2499217 2.2e-20 80.000
> 2129881 1167892 2.2e-20 80.000
> <snip>
> 
> ... several dozen thousand lines that look like that. 
> What I'm trying to do is remove one of pairs of "identical" lines that
> have identical columns 1, 2, and 4.
> The third column should be completely ignored. In my sample of the
> file, there are two lines that look like this:
> 
> 100039  2129881 3e-28   100.000
> 2129881 100039  3e-30   100.000
> 
> one of them should be removed by the script.
> The best i could do was this:
> 
> 
> foreach $x (@file) {
>         print $x;
>         foreach $n (@file) {
>                 ($blah, $blah2, $blah3, $blah4) = split "\t", $n;
>                 if ($x eq "$blah2\t$blah\t$blah3\t$blah4") { print
> "identical found\n"; undef $x; }
>         }
> }
> 
> This didn't work because it compared the third column too, and the
> algorithm was extremely slow.
> 
> If anyone could write something or give me an idea, i'd greatly
> appreciate it.
> 
> Ivan
> 



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

Date: Mon, 22 Oct 2001 03:49:39 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: perl algorithm
Message-Id: <3BD3CF93.9353B7AF@earthlink.net>

Ivan Kozik wrote:
[snip]
> What I'm trying to do is remove one of pairs of "identical" lines that
> have identical columns 1, 2, and 4.

I note that you have "identical" in quotes.  I assume you mean [from
your description below] that lines which have identical column 4s, and
have the columns 1 and 2 of one line match columns 2 and 1 of the other
line.

> The third column should be completely ignored. In my sample of the
> file, there are two lines that look like this:
> 
> 100039  2129881 3e-28   100.000
> 2129881 100039  3e-30   100.000
> 
> one of them should be removed by the script.

#!/usr/local/bin/perl -wMstrict
my %seen;
while( <STDIN> ) {
    $seen{ join $; => (split)[0,1,3] }++ and next;
    $seen{ join $; => (split)[1,0,3] }++ and next;
    print;
}
__END__

-- 
"What does stupid old man mean pidgin talk?
Shampoo does not talk like a bird."


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

Date: 22 Oct 2001 07:59:29 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: perl algorithm
Message-Id: <slrn9t7kfa.l03.rgarciasuarez@rafael.kazibao.net>

Benjamin Goldberg wrote in comp.lang.perl.misc:
> 
> #!/usr/local/bin/perl -wMstrict

What's this new idiom ?

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Mon, 22 Oct 2001 02:09:59 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: perl algorithm
Message-Id: <3bd3e26a@news.microsoft.com>

"F. Xavier Noria" <fxn@retemail.es> wrote in message
news:9r0fud$nu801@news1s.iddeo2.es...
> On Mon, 22 Oct 2001 01:33:35 GMT, Bob Walton <bwalton@rochester.rr.com>
wrote:
>
> : while(<DATA>){
>       #...
>   }
>
> Is there any benefit using DATA that way instead of a standard
> filehandle to a file on disk with the data to process? If so, which is
> the usual way to accomplish that?

No idea what you are talking about. DATA *is* a file handle, typically
pointing to a file on the disk although it might point to other resources
(pipes, sockets, ... ), too. And it is also the usual way.

> Would one wrap the original script
> in a shell script or whatever that copies it on top of the data file
> and then calls it?

???
What the heck are you talking about?

jue




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

Date: Mon, 22 Oct 2001 19:53:57 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: perl algorithm
Message-Id: <slrn9t7r5l.cnu.mgjv@martien.heliotrope.home>

On Mon, 22 Oct 2001 02:09:59 -0700,
	Jürgen Exner <jurgenex@hotmail.com> wrote:
> "F. Xavier Noria" <fxn@retemail.es> wrote in message
> news:9r0fud$nu801@news1s.iddeo2.es...
>> On Mon, 22 Oct 2001 01:33:35 GMT, Bob Walton <bwalton@rochester.rr.com>
> wrote:
>>
>> : while(<DATA>){
>>       #...
>>   }
>>
>> Is there any benefit using DATA that way instead of a standard
>> filehandle to a file on disk with the data to process? If so, which is
>> the usual way to accomplish that?
> 
> No idea what you are talking about. DATA *is* a file handle, typically
> pointing to a file on the disk although it might point to other resources
> (pipes, sockets, ... ), too. And it is also the usual way.

Nono. It _typically_ points to the current source file, just after the
__DATA__ token (and/or __END__ in the top level script). The user can
re-open it to some other file.

See the perldata documentation for a description.

>> Would one wrap the original script
>> in a shell script or whatever that copies it on top of the data file
>> and then calls it?

It is normally only used in example programs posted here, or to package
up default initialisaiton data in modules and/or scripts. But most
commonly you'll see it here.

To get back to your original question: "Is there any benefit using DATA
that way ... ?". The main advantage is, for posts to Usenet, that the
data and the program are neatly packaged up in one copy-and-paste-able
block of text. You don't have to create two files, one for the source,
and one for the data.

In real life programs, you'll hardly ever use it.

> ???
> What the heck are you talking about?

The DATA file handle, and why it is special.

Martien
-- 
                                | My friend has a baby. I'm writing
Martien Verbruggen              | down all the noises the baby makes so
                                | later I can ask him what he meant -
                                | Steven Wright


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

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 1977
***************************************


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