[24114] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6308 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 26 18:05:45 2004

Date: Fri, 26 Mar 2004 15:05:06 -0800 (PST)
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, 26 Mar 2004     Volume: 10 Number: 6308

Today's topics:
    Re: Building Perl with Open Watcom <mnieuw@don'tincludethis@zap.a2000.nl>
    Re: Building Perl with Open Watcom <nospam-abuse@ilyaz.org>
    Re: easier way for $scalar = /regexp/ ??? (Jay Tilton)
        Filehandles Referenced with a Variable <mikeflan@earthlink.net>
    Re: Filehandles Referenced with a Variable (Jay Tilton)
    Re: Filehandles Referenced with a Variable <mikeflan@earthlink.net>
    Re: Filehandles Referenced with a Variable <emschwar@pobox.com>
    Re: get multiple html files and convert to pdf <tore@aursand.no>
    Re: get multiple html files and convert to pdf <Me@myco.com>
    Re: get multiple html files and convert to pdf <tore@aursand.no>
    Re: Hash Reference Syntax <dwall@fastmail.fm>
    Re: Hash Reference Syntax <dwall@fastmail.fm>
    Re: how get next 5 lines? <dha@panix.com>
        How to make list of file dir and subdirectory with perl <tamara@agencija.com>
    Re: How to make list of file dir and subdirectory with  <Joe.Smith@inwap.com>
        Net::SSH  Need example how to use..can't find one... (cayenne)
    Re: Net::SSH  Need example how to use..can't find one.. <glex_nospam@qwest.invalid>
    Re: Perl:  Generate registration code <remorse@partners.org>
    Re: Perl:  Generate registration code <mgjv@tradingpost.com.au>
    Re: SCALAR(0x82dea94) (Anno Siegel)
        sendmail/cgi issue <joec@aracnet.com>
    Re: sendmail/cgi issue (David Efflandt)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 26 Mar 2004 23:23:40 +0100 (CET)
From: "Mat Nieuwenhoven" <mnieuw@don'tincludethis@zap.a2000.nl>
Subject: Re: Building Perl with Open Watcom
Message-Id: <zavrhjmncnay.hv7w7g0.pminews@news.text.chello.nl>

On Tue, 23 Mar 2004 21:12:47 +0000 (UTC), Ilya Zakharevich wrote:

:>[A complimentary Cc of this posting was sent to
:>Mat Nieuwenhoven 
:><mnieuw@zap.dontincludethis.a2000.nl>], who wrote in article 

which won't work because of the mangled address..

<Xns94B58B590DC5Emnieuwzapdontinclude@195.129.110.143>:
:>> >> As I said, this is only an uneducated guesswork on my side; I meant
:>> >> all the POSIXish stuff which is AFAIK missing in VAC: what I can
:>> >> immediately remember is exec() (which is used much more frequently
:>> >> than fork())
:>> 
:>> Watcom has a number of exec() funtions: execl, execle, execlp, execlpe,
:>> execv, execve, execvp and execvpe, plus their wide-char equivalents. It
:>> this what you mean? 
:>
:>Nope.  No misprint here.

I just looked  into the Perl 5.8.3 source, and I cannot see a single exec(
there. I see spawnl , spawnvp, execvp, execl  (e.g. in os2\os2.c around line
1419),
which is all standard clib stuff, also according to
http://www.opengroup.org/onlinepubs/007904975/functions/exec.html . What am I
missing?

:>> >> some minor-but-tedious stuff auto-translation of /dev/tty and
:>> >> /dev/null, etc.
:>> 
:>> This is not Posix stuff, surely?
:>
:>This is why I explicitly wrote "POSIXish", not POSIX.  ;-) I think all
:>reasonable POSIXification translate these too...

Ok, so if it's coded already there's no Watcom dependency.

:>> >> Doing tell()/seek() on text files is a problem with many compilers as
:>> >> well. 
:>> 
:>> You refer to the CR/LF problems when a file is opened in text mode?.
:>> Don't know how Watcom behaves here, I've never tried it, I tend to open
:>> files binary. Do you have a test case? 
:>
:>A sketch: open a large text file; read a thousand lines; read several
:>more bytes; tell(); repeat reading; seek() back; did you get to
:>exactly the same position in the *CRLF-translated* stream?

My tests indicates it works perfectly. 8600 line file with semi-random
spotchecks get it right every time (finding the nth line  with n changing
after each hit, then reading some, then store tell() pos plus next 12 bytes
in an array. At end, reverse through array-stored positions backward and read
and compare).

:>
:>> >> "Reliable" treatment of ^Z in text files?
:>> 
:>> What is supposed to happen when a ^Z is encountered? Normally it would
:>> be the last char of a file added by bad editors, but what if I paste it
:>> in the middle? 
:>
:>EMX treats ^Z specially only if it is the last byte of the file, or
:>(maybe only for TTY?) if it is immediately followed by \r? \n.

Reading stops on the very first EOF (x1A) which is encountered, even if it is
in the middle of the file. The EOF doesn't show up in the input stream.

:>> >> sbrk() (optional for perl, but may improve functionality a lot)?
:>> 
:>> Watcom does have a sbrk. Under non-DOS, it returns a newly allocated
:>> block of memory (rounded up to a multiple of 4k). Is this the one you
:>> mean?
:>
:>Good.  So at least one (optional) of the requirements is met...
:>
:>> >> Reliable command-line argument quoting/dequoting and globbing (so
:>> >> that arguments to spawnve() correspond 1-to-1 to argv[] array)?
:>> 
:>> There is no cmd line parsing in Watcom as far as I know.
:>
:>Com'on, you mean argc/argv is not supported?  ;-) A C compiler on OS/2
:>can't work without command-line parsing...

Of course Watcom has the normal argc/argv stuff. I thought you were referring
to some parsing library function. I'm not sure what you mean by
quoting/dequoting and globbing, though. I think Linux's getopt will treat
(ignore the single quotes) '-l h' and '-lh' the same, I'm pretty sure that
for Watcom the first case shows up as 2 arguments.

:>> >> wait()?
:>> 
:>> Watcom's wait returns the exit status and process ID of the first child
:>> process that terminates. 
:>
:>What about "Signal which killed it" part?

You are referring, I guess, to macros such as WTERMSIG which can interpret
the return value. Watcom doesn't have that. I'm not sure if it is easy to add
without breaking existing functionality, the returned status word is already
fully taken, although I think there's some room for a byte value in case of
an unhandled SIGTERM. But this could break existing code. 

:>> >> alarm()?
:>> 
:>> Not present in Watcom at the moment. Doesn't this send a particular
:>> signal to the process after a specified time? In the list of signals
:>> supported by Watcom (7 plus 3 OS/2 specific) I see nothing that looks
:>> like an alarm signal. 
:>
:>This would restrict functionality *a lot*.  Most scripts which need a
:>timed read() would use alarm()...

SIGALRM isn't part of the C spec, is it? It is Posix. Would be nice to add
but not so easy for the non-Linux targets (Dos, OS/2 and Win32), I think.
Linux has a kernel call for it.

Mat Nieuwenhoven








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

Date: Fri, 26 Mar 2004 22:50:52 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Building Perl with Open Watcom
Message-Id: <c42c4c$ju3$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Mat Nieuwenhoven
<mnieuw@don'tincludethis@zap.a2000.nl>], who wrote in article <zavrhjmncnay.hv7w7g0.pminews@news.text.chello.nl>:
> :>> Watcom has a number of exec() funtions: execl, execle, execlp, execlpe,
> :>> execv, execve, execvp and execvpe, plus their wide-char equivalents. It
> :>> this what you mean? 
> :>
> :>Nope.  No misprint here.
> 
> I just looked  into the Perl 5.8.3 source, and I cannot see a single exec(
> there. I see spawnl , spawnvp, execvp, execl  (e.g. in os2\os2.c around line
> 1419),
> which is all standard clib stuff, also according to
> http://www.opengroup.org/onlinepubs/007904975/functions/exec.html . What am I
> missing?

Probably it was me who is missing something.  Let me see (I'm
traveling, but I have a laptop with a pretty complete setup)...  You
are right, I mixed the Perl syntax `exec()' with C one; Perl's call is
translated to one of the appropriate C calls (IIRC, one uses spawn*()
with P_OVERLAY (sp?) flag).

> :>> >> some minor-but-tedious stuff auto-translation of /dev/tty and
> :>> >> /dev/null, etc.
> :>> 
> :>> This is not Posix stuff, surely?

> :>This is why I explicitly wrote "POSIXish", not POSIX.  ;-) I think all
> :>reasonable POSIXification translate these too...
> 
> Ok, so if it's coded already there's no Watcom dependency.

Hmm???  Since, as I expected, Watcom does no POSIXification, I do not
see how one can expect anything good here...

> :>A sketch: open a large text file; read a thousand lines; read several
> :>more bytes; tell(); repeat reading; seek() back; did you get to
> :>exactly the same position in the *CRLF-translated* stream?
> 
> My tests indicates it works perfectly. 8600 line file with semi-random
> spotchecks get it right every time (finding the nth line  with n changing
> after each hit, then reading some, then store tell() pos plus next 12 bytes
> in an array. At end, reverse through array-stored positions backward and read
> and compare).

All this with CRLF translation enabled?  Good, this is as good as EMX does...

> :>EMX treats ^Z specially only if it is the last byte of the file, or
> :>(maybe only for TTY?) if it is immediately followed by \r? \n.
> 
> Reading stops on the very first EOF (x1A) which is encountered, even if it is
> in the middle of the file. The EOF doesn't show up in the input stream.

In my experience, this logic creates a lot of trouble...

> :>> >> Reliable command-line argument quoting/dequoting and globbing (so
> :>> >> that arguments to spawnve() correspond 1-to-1 to argv[] array)?
> :>> 
> :>> There is no cmd line parsing in Watcom as far as I know.
> :>
> :>Com'on, you mean argc/argv is not supported?  ;-) A C compiler on OS/2
> :>can't work without command-line parsing...
> 
> Of course Watcom has the normal argc/argv stuff. I thought you were referring
> to some parsing library function. I'm not sure what you mean by
> quoting/dequoting and globbing, though. I think Linux's getopt will treat
> (ignore the single quotes) '-l h' and '-lh' the same, I'm pretty sure that
> for Watcom the first case shows up as 2 arguments.

I do not mean getopt.  Just the usual spawn*() and exec*() calls, and
whether the child will *always* see exactly the same argv/argc as
specified.  Also, how the child can glob the given arguments.  E.g.,
EMX's glob-the-argv function will not glob the arguments which were
quoted on the original command line.

> :>What about "Signal which killed it" part?
> 
> You are referring, I guess, to macros such as WTERMSIG which can interpret
> the return value. Watcom doesn't have that. I'm not sure if it is easy to add
> without breaking existing functionality, the returned status word is already
> fully taken, although I think there's some room for a byte value in case of
> an unhandled SIGTERM. But this could break existing code. 

Such things are impossible to add as an afterthought.  To do this, EMX
restricts the return value to 8-bit (as POSIX does)...  But in the
Perl case, this will restrict the functionality of working scripts
only a tiny bit; however, debugging/test-suite will be less reliable.

> :>This would restrict functionality *a lot*.  Most scripts which need a
> :>timed read() would use alarm()...
> 
> SIGALRM isn't part of the C spec, is it?

Com'on, you know that it is not possible to write anything useful
using C spec's alone (with a few obvious exceptions ;-).  You can't
even read a directory....  So mentioning C specs in context of porting
is futile...

Hope this helps,
Ilya


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

Date: Fri, 26 Mar 2004 19:55:20 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: easier way for $scalar = /regexp/ ???
Message-Id: <40648a9b.4320254@news.erols.com>

"David K. Wall" <dwall@fastmail.fm> wrote:

: Rocky <PerlGuRu2b@bobotheclown.org> wrote:
: 
: > if ($_ =~ /^Job\sserver:\s+(.*)$/)     { $servername = $1;}
: > isn't it possible to just say 
: > $servername = ???
: > I can't seem to find a good example.
: 
: my $servername = $1 if /^Job\sserver:\s+(.*)$/;

Doing it like that isn't a very good idea.  From perlsyn:

    NOTE: The behaviour of a "my" statement modified with a
    statement modifier conditional or loop construct (e.g. "my $x
    if ...") is undefined. The value of the "my" variable may be
    "undef", any previously assigned value, or possibly anything
    else. Don't rely on it. Future versions of perl might do
    something different from the version of perl you try it out
    on. Here be dragons.

Some alternatives:

    my($servername) = /^Job\sserver:\s+(.*)$/;

    my $servername  = ( /^Job\sserver:\s+(.*)$/ )[0];



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

Date: Fri, 26 Mar 2004 20:51:25 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Filehandles Referenced with a Variable
Message-Id: <406497E7.D78B8566@earthlink.net>


The solution I found to the following problem requires me to
comment out the 'use strict' line, and I'm looking for a
solution that does not require me to comment out 'use strict'.

A modified version of the script below will be run on a flat
file that contains about 1.7 million rows (records).  The script
is simply going to print the 1.7 million rows out to about
65 different files (one file for each state or territory).  No
record modification is needed, but some records will be
printed out to more than one file, depending on data
contained within each record.

I could hard wire the filehandles, but was looking for a more
elegant way.  So I decided to use a hash of typeglob
notations to specify which file to print out to.  The method
that works for me is to use print { $type{$st} } "$st  "; where
{ $type{$st} } contains the file handle typeglob.
I got this { $type{$st} } from the Cookbook recipe 7.16.
It's apparently a 'proper block'.  But as I said, it requires
me to comment out 'use strict'.  Not a fatal problem, but
I'm looking for a better way.


Thanks for any help supplied.


Mike
(who no longer considers himself a total newbie, just a novice)



Before I stumbled on the solution above, I tried:

if ($st eq 'DC') {
    $out = *$st;
    print $out "$st  ";

but it gives error: Can't use string ("DC") as a symbol ref
with "strict refs".


I also tried:

my %type = (
 "DC" => "*DC",
 "AL" => "*AL"
 );

if ($st eq 'DC') {
    print $type{$st} "$st  ";
}

but it gives error:  String found where operator expected.


Then I tried:
if ($st eq 'DC') {
    print { $type{$st} } "$st  "; #Added brackets from Cookbook7.16
}
but it gives error:  String found where operator expected.


SO I REMOVED THE USE STRICT AND IT WORKS




For those very few people that like to see everything:

#use strict;
use warnings;

my $infile = 'USAshorter.txt';

my $fileout = 'states.txt';
my ($line, $stm, $state, $st, @sttemp, %count, $k, $v);
my $num=0;
my $tot=0;
my @states = ('AK', 'AL', 'AR', 'AS', 'AZ', 'CA', 'CO', 'CT', 'DC',
'DE', 'FL', 'FM', 'GA', 'GU', 'HI', 'IA', 'ID', 'IL', 'IN', 'KS', 'KY',
'LA', 'MA', 'MD', 'ME', 'MH', 'MI', 'MN', 'MO', 'MP', 'MS', 'MT', 'NC',
'ND', 'NE', 'NH', 'NJ', 'NM', 'NV', 'NY', 'OH', 'OK', 'OR', 'PA', 'PR',
'PW', 'RI', 'SC', 'SD', 'TN', 'TX', 'UM', 'UT', 'VA', 'VI', 'VT', 'WA',
'WI', 'WV', 'WY');

my %type = (
 "DC" => "*DC",
 "AL" => "*AL"
 );

chdir 'C:\Copy2';

open OUT, ">", $fileout or die "Cannot open $fileout: $!";
open DC, ">DC.txt" or die "Cannot open DC.txt: $!";


open IN, "<", $infile or die "Cannot open $infile: $!";

while ($line = <IN>) {
    $num++;
    print "Did not find good pattern at line # $num.\n$line\n\n" unless
($line =~ m/\t([^\t]*)\t[^\t]*\n$/);
    $stm = $1;

    print "problem with record # $num\n$line\n\n" unless (@sttemp = grep
$line =~ m/$_, /i, @states);

    foreach $st (@sttemp) {
        $count{$st}++;
        if ($st eq 'DC') {
            print { $type{$st} } "$line";
        }
    }
    print "$num\n" if $num % 50000 == 0;
}
close IN;

foreach $state (sort keys %count) {
    print "$state will be written $count{$state} times.\n";
    print OUT "$state will be written $count{$state} times.\n";
    $tot += $count{$state};
}

print "\n\n";
print OUT "\n\n";
print "$num records will be written $tot times.\n";
print OUT "$num records will be written $tot times.\n";
print "\n\n";
print OUT "\n\n";

close OUT;
close DC;

__END__




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

Date: Fri, 26 Mar 2004 21:28:10 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Filehandles Referenced with a Variable
Message-Id: <40649de2.9255759@news.erols.com>

Mike Flannigan <mikeflan@earthlink.net> wrote:

: The solution I found to the following problem requires me to
: comment out the 'use strict' line, and I'm looking for a
: solution that does not require me to comment out 'use strict'.

A worthwhile design point.

: I could hard wire the filehandles, but was looking for a more
: elegant way.  So I decided to use a hash of typeglob
: notations to specify which file to print out to.  The method
: that works for me is to use print { $type{$st} } "$st  "; where
: { $type{$st} } contains the file handle typeglob.
: I got this { $type{$st} } from the Cookbook recipe 7.16.
: It's apparently a 'proper block'.  But as I said, it requires
: me to comment out 'use strict'.

Only because $type{$st} is not really a typeglob.

: Before I stumbled on the solution above, I tried:
: 
: if ($st eq 'DC') {
:     $out = *$st;
:     print $out "$st  ";
: 
: but it gives error: Can't use string ("DC") as a symbol ref
: with "strict refs".
: 
: 
: I also tried:
: 
: my %type = (
:  "DC" => "*DC",
           ^^^^^
:  "AL" => "*AL"
           ^^^^^
:  );

Those are strings, not typeglobs.

    my %type = (
     "DC" => *DC,
     "AL" => *AL
    );

: if ($st eq 'DC') {
:     print $type{$st} "$st  ";
: }
: 
: but it gives error:  String found where operator expected.

Naturally.

: Then I tried:
: if ($st eq 'DC') {
:     print { $type{$st} } "$st  "; #Added brackets from Cookbook7.16
: }
: but it gives error:  String found where operator expected.

Really?  It should give the error: 
Can't use string ("*DC") as a symbol ref while "strict refs" in use 



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

Date: Fri, 26 Mar 2004 21:58:15 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Filehandles Referenced with a Variable
Message-Id: <4064A792.3CB723B2@earthlink.net>


Jay Tilton wrote:

> :
> : my %type = (
> :  "DC" => "*DC",
>            ^^^^^
> :  "AL" => "*AL"
>            ^^^^^
> :  );
>
> Those are strings, not typeglobs.
>
>     my %type = (
>      "DC" => *DC,
>      "AL" => *AL
>     );
>

Right you are.  Thank you.

I have since discovered that I can give up on the hash, but
I'm back to where I need to remove the 'use strict'.

When I run the code below, it runs fine.  But if I uncomment
out 'use strice' is gives error:
Can't use string ("AK") as a symbol ref while "strict refs"
in use at line 16.  Making it a 'proper block' doesn't help
either.  Any idea why?


#use strict;
use warnings;

my $infile = 'USAshorter.txt';

my $fileout = 'states.txt';
my ($line, $stm, $state, $st, @sttemp, %count, $k, $v);
my $num=0;
my $tot=0;
my @states = ('AK', 'AL', 'AR', 'AS', 'AZ', 'CA', 'CO', 'CT', 'DC', 'DE',
'FL', 'FM', 'GA', 'GU', 'HI', 'IA', 'ID', 'IL', 'IN', 'KS', 'KY', 'LA',
'MA', 'MD', 'ME', 'MH', 'MI', 'MN', 'MO', 'MP', 'MS', 'MT', 'NC', 'ND',
'NE', 'NH', 'NJ', 'NM', 'NV', 'NY', 'OH', 'OK', 'OR', 'PA', 'PR', 'PW',
'RI', 'SC', 'SD', 'TN', 'TX', 'UM', 'UT', 'VA', 'VI', 'VT', 'WA', 'WI',
'WV', 'WY');

chdir 'C:\Copy2';

foreach $st (@states) {
    open *$st, ">$st.txt" or die "Cannot open $st.txt: $!"; # THIS IS
LINE 16
}

open OUT, ">", $fileout or die "Cannot open $fileout: $!";

open IN, "<", $infile or die "Cannot open $infile: $!";

while ($line = <IN>) {
    $num++;
    print "Did not find good pattern at line # $num.\n$line\n\n" unless
($line =~ m/\t([^\t]*)\t[^\t]*\n$/);
    $stm = $1;

    print "problem with record # $num\n$line\n\n" unless (@sttemp = grep
$line =~ m/$_, /i, @states);

#    print "Did not find 2 character state at line # $num.\n$line\n\n"
unless ($stm =~ m/^(\w{2}),[^;]*\n?$/);
    foreach $st (@sttemp) {
        $count{$st}++;
        if ($st eq 'DC') {
            print { *$st } "$line";
        }
    }
    print "$num\n" if $num % 50000 == 0;
}
close IN;

foreach $state (sort keys %count) {
    print "$state will be written $count{$state} times.\n";
    print OUT "$state will be written $count{$state} times.\n";
    $tot += $count{$state};
}

print "\n\n";
print OUT "\n\n";
print "$num records will be written $tot times.\n";
print OUT "$num records will be written $tot times.\n";
print "\n\n";
print OUT "\n\n";

close OUT;

foreach $st (@states) {
    close *$st;
}

__END__




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

Date: Fri, 26 Mar 2004 15:35:49 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Filehandles Referenced with a Variable
Message-Id: <eto7jx744oq.fsf@fc.hp.com>

Mike Flannigan <mikeflan@earthlink.net> writes:
> When I run the code below, it runs fine.  But if I uncomment
> out 'use strice' is gives error:
> Can't use string ("AK") as a symbol ref while "strict refs"
> in use at line 16.  Making it a 'proper block' doesn't help
> either.  Any idea why?

<snip>

> foreach $st (@states) {
>     open *$st, ">$st.txt" or die "Cannot open $st.txt: $!"; # THIS IS
> LINE 16
> }

@states is an array of strings.  So when you try to treat $st as if
it's a reference to a filehandle, when it's a string, naturally it
says, "Can't use string as a symbol ref".  Furthermore, you open all
these files, and then do nothing with them.  I don't get it-- are you
just trying to see if you can open the files without actually opening
them?  If so, then you can replace that with:

map { -r "$_.txt" or die "Cannot open $_.txt: $!" } @states;

> while ($line = <IN>) {
>     $num++;

You can just use $. (perldoc perlvar)

>     print "Did not find good pattern at line # $num.\n$line\n\n" unless
>  ($line =~ m/\t([^\t]*)\t[^\t]*\n$/);
>     $stm = $1;

This variable could stand to be named more verbosely-- I have no idea
what a 'stm' is, and your code doesn't help me much.

>     print "problem with record # $num\n$line\n\n" unless (@sttemp = grep
> $line =~ m/$_, /i, @states);

FYI, this error message doesn't help much-- it says there's a problem,
which is good, but not what the problem is, or how to fix it.  I'm on
a campaign recently to get better error messages, so you may take this
with a grain or two of salt.  Also, since @sttemp appears to be an
array with the names of the states found in $line, perhaps a name like
@statesfound might help a reader understand better what you're trying
to do with it.

> #    print "Did not find 2 character state at line # $num.\n$line\n\n"
> unless ($stm =~ m/^(\w{2}),[^;]*\n?$/);

I think this unless should be commented out as well; it doesn't
actually do anything as written.

>     foreach $st (@sttemp) {
>         $count{$st}++;
>         if ($st eq 'DC') {
>             print { *$st } "$line";
>         }

This print line is probably going to cause you trouble as well; you're
confusing symrefs and strings again.  Also, don't quote $line there;
it's unnecessary, and could cause trouble later.

In this case, $st is a string, 'DC'.  You're trying to print to a
filehandle, which I imagine you thought you were opening on line 16
above.  If you're only printing to 'DC.txt', then maybe you should
open it just before that loop, and close it afterwards:

open my $dc_count, '>', "DC.txt" or die "bah: $!";
foreach(...) {
  if(...) {
     print $dc_count $line;
}
close $dc_count or die "grr: $!";

If you're going to be doing this for more than one state later on,
maybe your loop on line 16 should use a hash instead:

my %state_files;
foreach my $state (@states) {
  open $state_files{$state}, '>', "$state.txt" or die "bah: $!"
}

Then you can do something like:

foreach my $state (@sttemp) {
  $count{$state}++;
  print $state_files{$state} $line; # or maybe
  print $state_files{$state} $line if $state eq 'DC';
}

and at the end of the program, of course:

foreach my $state(keys %state_files) {
  close $state_files{$state} or die "bah: $!";
}

>     }
>     print "$num\n" if $num % 50000 == 0;
> }

Again, you can use $. here.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Fri, 26 Mar 2004 20:46:42 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: get multiple html files and convert to pdf
Message-Id: <pan.2004.03.26.19.46.39.829738@aursand.no>

On Fri, 26 Mar 2004 20:49:14 +0530, AB wrote:
>> You want us to whipe your ass, too? :)  What have you tried so far?  What

> That comment was uncalled for and downright vulgar.

Not necessarily; didn't you see the smiley?

>> approaches did you consider?  What's not working?

> Looking at the demented language you use, dont think explaining that to 
> *you* would be of any help.

With that attitude, you can't expect to get much help from people in this
group.  The reason is that we encourage people to _try themselves_ before
posting here for help.

To me it doesn't seem like you've tried much.  It seems to me that you'd
like someone here to solve the problem for you.  And I want a toilet made
out of gold.

> Try to learn some netiquette before you comment on someone [...]

You could try that yourself.  Have you read the posting guidelines for
this group?


-- 
Tore Aursand <tore@aursand.no>
"Writing is a lot like sex. At first you do it because you like it.
 Then you find yourself doing it for a few close friends and people you
 like. But if you're any good at all, you end up doing it for money."
 -- Unknown


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

Date: Sat, 27 Mar 2004 01:32:17 +0530
From: AB <Me@myco.com>
Subject: Re: get multiple html files and convert to pdf
Message-Id: <v509c.57$sP4.449@news.oracle.com>



Tore Aursand wrote:

> On Fri, 26 Mar 2004 20:49:14 +0530, AB wrote:
> 
>>>You want us to whipe your ass, too? :)  What have you tried so far?  What
> 
> 
>>That comment was uncalled for and downright vulgar.
> 
> 
> Not necessarily; didn't you see the smiley?
> 
> 
A smiley has nothing to do with vulgarity :) Specifically, it does not 
excuse it.

>>>approaches did you consider?  What's not working?
> 
> 
>>Looking at the demented language you use, dont think explaining that to 
>>*you* would be of any help.
> 
> 
> With that attitude, you can't expect to get much help from people in this
> group.  The reason is that we encourage people to _try themselves_ before
> posting here for help.
> 
I have been a reader of this group for quite a long time. And 
thankfully, my attitude has in no way hindered my quest for knowledge. 
(Please refer to other branches in this post). :)

> To me it doesn't seem like you've tried much.  It seems to me that you'd
> like someone here to solve the problem for you.  And I want a toilet made
> out of gold.
Yes i did not try much "code". Because I needed some place to start.
I do not want someone to solve my problem.
And no, I do not want a toilet made of gold.
> 
> 
>>Try to learn some netiquette before you comment on someone [...]
> 
> 
> You could try that yourself.  Have you read the posting guidelines for
> this group?
> 
Yes I have . All through. Which is why I would not like this to turn 
into a flame :)
> 
Regards
AB



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

Date: Fri, 26 Mar 2004 22:36:02 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: get multiple html files and convert to pdf
Message-Id: <pan.2004.03.26.21.17.10.852433@aursand.no>

On Sat, 27 Mar 2004 01:32:17 +0530, AB wrote:
>>> That comment was uncalled for and downright vulgar.

>> Not necessarily; didn't you see the smiley?

> A smiley has nothing to do with vulgarity :) Specifically, it does not
> excuse it.

I could of course have written the sentence slightly different, but the
point would still have been valid;

Do you want us to do the job for you?  What have you tried so far?  What
doesn't work?

>>> Try to learn some netiquette before you comment on someone [...]

>> You could try that yourself.  Have you read the posting guidelines for
>> this group?

> Yes I have. All through.

Good.  Then you know what to do - this time and next time.  Most of your
original question is answered in the Perl documentation, while the other
parts are either done by existing modules [1] or aquired by searching [2]
the Internet for information.

[1] <http://www.cpan.org/> and <http://search.cpan.org/>
[2] <http://www.google.com/>


-- 
Tore Aursand <tore@aursand.no>
"A teacher is never a giver of truth - he is a guide, a pointer to the
 truth that each student must find for himself.  A good teacher is
 merely a catalyst." -- Bruce Lee


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

Date: Fri, 26 Mar 2004 19:23:38 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Hash Reference Syntax
Message-Id: <Xns94B8926C68377dkwwashere@216.168.3.30>

Andrew Bell <acbell@iastate.edu> wrote:

> I am having trouble passing a hash reference to a subroutine.  Any
> help on the syntax would be helpful.
> 
> $hash{$k1}{$k2} = "foo";
> &doSub(\($hash{$k1}));

Chances are you don't need the & on the sub call. See perlsub.

    doSub( $hash{$k1} );

 
> sub doSub {
>   my($r) = @_;
> 
>   if (defined(${$r}{$k2)) {
                     ^   ^
Where's the matching '}'?

It's probably easier and more idiomatic to write

    if (defined $r->{$k2} ) {

>     do something;
>  } 
>}
> 
> I get an error on the line containing the "defined" statement 
> saying:
> 
> Not a HASH reference at file.pl line xx.

As you should have. :-)


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

Date: Fri, 26 Mar 2004 19:27:40 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Hash Reference Syntax
Message-Id: <Xns94B8931B2B52dkwwashere@216.168.3.30>

Paul Lalli <ittyspam@yahoo.com> wrote:

> On Fri, 26 Mar 2004, Andrew Bell wrote:
> 
>> I am having trouble passing a hash reference to a subroutine. 
>> Any help on the syntax would be helpful.

[snip Paul's response]

Oops. I looked to see if anyone had responded, but I was in non-
threaded mode then (looking at the most recent posts) and missed your 
followup. Oh well.


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

Date: Fri, 26 Mar 2004 21:32:09 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: how get next 5 lines?
Message-Id: <slrnc698ap.kl0.dha@panix2.panix.com>

In article <8vc860l0c6ifrepujr8pm89upcgua6pp59@4ax.com>, Geoff Cox wrote:
> Hello
> 
> I am opening a file to look for a piece of data and having found that
> data I want to read the next 5 lines...as there is another bit of data
> on one of those lines...

I wouldn't recommend it for real work, but just for fun....

$l=$. + 4;<> until $. == $l;print scalar <>;

dha


-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Your question doesn't make any sense. You might as well ask whether
it is possible to grow vegetables from a painting, without becoming
Wednesday first.       - Abigail, c.l.p.misc


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

Date: Fri, 26 Mar 2004 22:40:50 -0800
From: "Tamara" <tamara@agencija.com>
Subject: How to make list of file dir and subdirectory with perl for windows?
Message-Id: <c427vl$ek0$1@ls219.htnet.hr>

How to make list of file dir and subdirectory with perl for windows?
TNX.




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

Date: Fri, 26 Mar 2004 22:14:31 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: How to make list of file dir and subdirectory with perl for windows?
Message-Id: <bX19c.11928$gA5.181023@attbi_s03>

Tamara wrote:

> How to make list of file dir and subdirectory with perl for windows?

C:\>perl -MFile::Find -le "find(\&wanted,'c:/perl'); sub wanted {print}"
C:\>perldoc File::Find


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

Date: 26 Mar 2004 13:31:37 -0800
From: chilecayenne@yahoo.com (cayenne)
Subject: Net::SSH  Need example how to use..can't find one...
Message-Id: <2deb3d1.0403261331.1fdd27f6@posting.google.com>

Hello all!

I'm trying to teach myself Perl, and I've gotten along so far. I've
been able to use the DBI module to connect to Oracle. I was able to
find examples of how to use this.

I now need to use Net::SSH to use ssh from one machine to another to
do some things.

I cannot, however, find any clear examples how to use this package.
I've looked at the .pm...but, am not advanced enough to know what to
do with it. Can someone show me an example of how to use this or point
me to a link with and example of it in use?

The only examples I've found out there is for Net::SSH::Perl.....and
my SA says this is not an option to put on the box...

Thanks in advance!! I really like Perl so far...just gonna take a lot
of working with to get it down.

chilecayenne


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

Date: Fri, 26 Mar 2004 16:06:59 -0600
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: Net::SSH  Need example how to use..can't find one...
Message-Id: <8Q19c.249$Qv1.92719@news.uswest.net>

cayenne wrote:
> Hello all!
> 
> I'm trying to teach myself Perl, and I've gotten along so far. I've
> been able to use the DBI module to connect to Oracle. I was able to
> find examples of how to use this.
> 
> I now need to use Net::SSH to use ssh from one machine to another to
> do some things.
> 
> I cannot, however, find any clear examples how to use this package.
> I've looked at the .pm...but, am not advanced enough to know what to
> do with it. Can someone show me an example of how to use this or point
> me to a link with and example of it in use?

If you have the .pm, reading the documentation that comes with it, 
instead of the code, is done by running "perldoc":

perldoc Net::SSH

or if it's not installed on the system and is in your local directory

perldoc ./SSH.pm

or simply look at the documentation on CPAN

http://search.cpan.org/~ivan/Net-SSH-0.08/SSH.pm

Define "do some things".  That's too general.  Depending on what 
"things" you want to do you'd use ssh_cmd, sshopen2, or sshopen3.  To 
see what open2 and open3 are, check the documentation for perlipc 
(perldoc perlipc), or more specifically IPC::Open2 and IPC::Open3.


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

Date: Fri, 26 Mar 2004 15:25:43 -0500
From: Richard Morse <remorse@partners.org>
Subject: Re: Perl:  Generate registration code
Message-Id: <remorse-161A5A.15254226032004@plato.harvard.edu>

In article <c2c15952.0403261030.bb12901@posting.google.com>,
 john_1998@hotmail.com (John) wrote:

> I am new to Perl.  I want to write a Perl script that generates a
> registration code on my website.  It's basically a hex of the week of
> the year and year, plus and multiplied by some number.  I have a
> sample of what I would like in VB.  Can someone help convert this to
> Perl.  I'm hoping it's as simple as VB.  Thanks for your help...
> 
> ------- VB Code ------------
> Sub RegCode()
> Dim strCode as String
> strCode = Hex(((DatePart("ww", Date) & Year(Date)) + 12345) * 12345)
> Debug.Print strCode
> End Sub
> ---------------------------

To get the date, look at the 'localtime' function.  It doesn't supply a 
week of the year, so if it absolutely must be based off of the week, you 
might need to look at various date modules from CPAN (http://search.cpan.org).

When you say "hex of the ...", presumably you mean a hex string 
representing the number that you generate.  The sprintf function will do 
this:
   perl -e "print sprintf('%x', 24), qq{\n}"
returns:
   18

HTH,
Ricky


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

Date: Sat, 27 Mar 2004 08:30:16 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Perl:  Generate registration code
Message-Id: <slrnc69878.dn2.mgjv@martien.heliotrope.home>

On 26 Mar 2004 10:30:13 -0800,
	John <john_1998@hotmail.com> wrote:
> 
> 
> I am new to Perl.  I want to write a Perl script that generates a
> registration code on my website.  It's basically a hex of the week of
> the year and year, plus and multiplied by some number.  I have a
> sample of what I would like in VB.  Can someone help convert this to
> Perl.  I'm hoping it's as simple as VB.  Thanks for your help...

The first thing you need to do is define what you (or VB) means by "the
week of the year", since there are various valid definitions out there
that say when the first week of the year starts.

> strCode = Hex(((DatePart("ww", Date) & Year(Date)) + 12345) * 12345)

To "hex" (awful expression) something in Perl, you can use the sprintf
function. Documentation in perlfunc. You can get the current year with
localtime(), again documented in perlfunc.

To get better help, you should probably also explain what the & operator
does in VB, just to help the people out who have ever been able to bring
themselves to touch that environment.

Martien
-- 
                        | 
Martien Verbruggen      | prepBut nI vrbLike adjHungarian! qWhat's
                        | artThe adjBig nProblem? -- Alec Flett
                        | 



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

Date: 26 Mar 2004 19:08:47 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: SCALAR(0x82dea94)
Message-Id: <c41v3v$e34$2@mamenchi.zrz.TU-Berlin.DE>

Ala Qumsieh <xxala_qumsiehxx@xxyahooxx.com> wrote in comp.lang.perl.misc:
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrnc6789v.m6i.tadmc@magna.augustmail.com...
> 
> > Having advice repeatedly ignored tends to make you want to
> > just stop giving advice.
> >
> > I give up too.
> 
> Is anybody else feeling even more scared to give out credit card info on the
> web?
> The fact that this sub is called "billing_engine" isn't exactly re-assuring
> ...

My, you're right.  This amateur (in the most disparaging sense the word is
capable of assuming) presumably has also written a "security_engine" that
deals with credit card numbers.

What a horror of a program.

Anno


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

Date: Fri, 26 Mar 2004 11:00:53 -0800
From: Joe Cipale <joec@aracnet.com>
Subject: sendmail/cgi issue
Message-Id: <40647DE5.8D8D56A8@aracnet.com>

I have a file that is generated via CGI. Once the user is happy with the
file, I want to send the file to a dedicated email address. The problem
is this. Once the user decides to process the file and send it off to
the email address, the file inforamtion IS NOT included in the body of
the email that is delivered.

The funny thing is, I can encode/use this (code below) simply as a
generic perl script, and the data is delivered as expected. It is not
being collected and deliverd from with the CGI script via the web.

Can someone tell me what I am missing here?
 You can email me directly if you wish. Thanks in advance,

Joe Cipale
-- 
open(FILE, "$read_path/$dte");
open(SM, "| /usr/sbin/sendmail -t -fjoec\@aracnet.com");
my @email_body = <FILE>;
print "@email_body";

print SM <<EOF;
From: evbc\@aracnet.com
To: joec\@aracnet.com
Subject: Race Refund Request

EOF

print SM  @email_body;   # Here's where the body gets 
                         # printed into the message.
close(FILE);
close(SM);

#----------------------------------------------------------#
#                "Don't fear the penguin!"                 #
#----------------------------------------------------------#
# Registered Linux user: #309247     http://counter.li.org #
#----------------------------------------------------------#


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

Date: Fri, 26 Mar 2004 19:52:52 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: sendmail/cgi issue
Message-Id: <slrnc692gk.k88.efflandt@typhoon.xnet.com>

On Fri, 26 Mar 2004 11:00:53 -0800, Joe Cipale <joec@aracnet.com> wrote:
> I have a file that is generated via CGI. Once the user is happy with the
> file, I want to send the file to a dedicated email address. The problem
> is this. Once the user decides to process the file and send it off to
> the email address, the file inforamtion IS NOT included in the body of
> the email that is delivered.
> 
> The funny thing is, I can encode/use this (code below) simply as a
> generic perl script, and the data is delivered as expected. It is not
> being collected and deliverd from with the CGI script via the web.
> 
> Can someone tell me what I am missing here?
>  You can email me directly if you wish. Thanks in advance,

You are missing the test to see if your open() is successful, and print 
the error $! somewhere useful (like to the browser) if not.  Assuming you 
are setting a proper Content-type header before this, does the body 
content show up in the browser (from the: print "@email_body";)?

> Joe Cipale
> -- 
> open(FILE, "$read_path/$dte");
> open(SM, "| /usr/sbin/sendmail -t -fjoec\@aracnet.com");
> my @email_body = <FILE>;
> print "@email_body";
> 
> print SM <<EOF;
> From: evbc\@aracnet.com
> To: joec\@aracnet.com
> Subject: Race Refund Request
> 
> EOF
> 
> print SM  @email_body;   # Here's where the body gets 
>                          # printed into the message.
> close(FILE);
> close(SM);
> 
> #----------------------------------------------------------#
> #                "Don't fear the penguin!"                 #
> #----------------------------------------------------------#
> # Registered Linux user: #309247     http://counter.li.org #
> #----------------------------------------------------------#


-- 
David Efflandt - All spam ignored  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/


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

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


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