[22514] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4735 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 20 14:10:07 2003

Date: Thu, 20 Mar 2003 11:05:08 -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           Thu, 20 Mar 2003     Volume: 10 Number: 4735

Today's topics:
    Re: array namen dynamisch generieren <jurgenex@hotmail.com>
    Re: Array reference argument to subroutine problem <grazz@nyc.rr.com>
    Re: Array reference argument to subroutine problem (Anno Siegel)
    Re: Can't access array element in Class::Struct structu (M Browning)
    Re: Date Calculation <Steffen.Beyer@de.bosch.com>
    Re: doubts on \n <goldbb2@earthlink.net>
    Re: doubts on \n <mjcarman@mchsi.com>
    Re: doubts on \n <fxn@hashref.com>
    Re: doubts on \n <fxn@hashref.com>
    Re: doubts on \n <goldbb2@earthlink.net>
    Re: doubts on \n (Anno Siegel)
        getOpenFile with -initialdir <pzerwetz@yaccom.com>
    Re: How can I....? <jurgenex@hotmail.com>
    Re: how to check file size (very large! > 2GB) using Pe <goldbb2@earthlink.net>
    Re: How to include data stamps in a script?? (John Smith)
    Re: Need a little help with a short script <tore@aursand.no>
    Re: Open file and print out contents from array <perl-dvd@darklaser.com>
    Re: Open file and print out contents from array (Jacques Veldhuijzen)
    Re: Open file and print out contents from array (Tad McClellan)
    Re: Reverse assignment operator <torelg@start.no>
    Re: Reverse assignment operator <tassilo.parseval@rwth-aachen.de>
    Re: Reverse assignment operator <goldbb2@earthlink.net>
    Re: running a script on multiple files in a directory <grazz@nyc.rr.com>
    Re: Socket Problem In Perl <goldbb2@earthlink.net>
    Re: Text::ParseWords or Text::CSV <goldbb2@earthlink.net>
    Re: UDP Comms Problem <goldbb2@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 20 Mar 2003 14:38:59 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: array namen dynamisch generieren
Message-Id: <7okea.40916$Ad6.25521@nwrddc01.gnilink.net>

Ulrich Gödert wrote:
> ich bin auf der Suche nach einer Möglichkeit, array namen dynamisch
> zur Laufzeit zu generieren. Dabei sollen per $t1=substr($var,1,1) und
> einem festen Teil "foo" der Name zusammengesetzt werden. Das Ergebis
> sollte ein @afoo, @bfoo, ... sein.Ein hash ist keine Lösung, da ich
> die arrays mit Namen später brauche

No, you don't.
Please explain why can't you use a hash %myfooarrays with the elements
$myfooarrays{a} and $myfooarrays{b} instead of @afoo and @bfoo everywhere in
your program.

Beside that: please see "perldoc -q variable":
    "How can I use a variable as a variable name?"

jue




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

Date: Wed, 19 Mar 2003 02:27:16 GMT
From: Steve Grazzini <grazz@nyc.rr.com>
Subject: Re: Array reference argument to subroutine problem
Message-Id: <8AQda.532$DQ.505245@twister.nyc.rr.com>

dw <me@verizon.invalid> wrote:
> "Tad McClellan" <tadmc@augustmail.com> wrote:
>> dw <me@verizon.invalid> wrote:
>>
>> >    firstSub( \(1..5), \("A".."E"));
>>
>> Why/how does that end up working? (I tried it with 5.6.1
>> & 5.8.0).
>>
>> perlref.pod says we should be getting 10 references from 
>> that, not 2:
 ...
> 
> Thank you Tad.  I wasn't thinking so I just glazed over the 
> fact that the reference gets distributed across the contents
> of the list.  However, it appears to work this way when you 
> use the range operator.  According to perlop for the range 
> operator, "In list context, it returns an array of values..."  
                                            ^^^^^

Hmmm... 

  ~ > perl -MO=Concise -e'\(1..5)'
  c  <@> leave[t1] vKP/REFC ->(end)
  6     <0> enter ->7
  7     <;> nextstate(main 1 -e:1) v ->8
  b     <1> refgen vK/1 ->c
  -        <1> ex-list lKRM ->b
  8           <0> pushmark sRM ->9
  a           <1> rv2av lKPRM/1 ->b
  9              <$> const(AV ) s ->a
                     ^^^^^^^^^^

So the docs are correct, then.

But I would have needed heavy emphasis on the word *array* 
to get the point.  Whenever I see something like "returns 
an array of values", I do an automatic s/array/list/.

And the perlop here [5.8] actually says "an list of values", 
so maybe I'm not the only one doing auto-translation.  :-)

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'


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

Date: 20 Mar 2003 17:50:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Array reference argument to subroutine problem
Message-Id: <b5cv20$6b7$1@mamenchi.zrz.TU-Berlin.DE>

Steve Grazzini  <grazz@nyc.rr.com> wrote in comp.lang.perl.misc:
> dw <me@verizon.invalid> wrote:
> > "Tad McClellan" <tadmc@augustmail.com> wrote:
> >> dw <me@verizon.invalid> wrote:
> >>
> >> >    firstSub( \(1..5), \("A".."E"));
> >>
> >> Why/how does that end up working? (I tried it with 5.6.1
> >> & 5.8.0).
> >>
> >> perlref.pod says we should be getting 10 references from 
> >> that, not 2:
> ...
> > 
> > Thank you Tad.  I wasn't thinking so I just glazed over the 
> > fact that the reference gets distributed across the contents
> > of the list.  However, it appears to work this way when you 
> > use the range operator.  According to perlop for the range 
> > operator, "In list context, it returns an array of values..."  
>                                             ^^^^^
> 
> Hmmm... 
> 
>   ~ > perl -MO=Concise -e'\(1..5)'
>   c  <@> leave[t1] vKP/REFC ->(end)
>   6     <0> enter ->7
>   7     <;> nextstate(main 1 -e:1) v ->8
>   b     <1> refgen vK/1 ->c
>   -        <1> ex-list lKRM ->b
>   8           <0> pushmark sRM ->9
>   a           <1> rv2av lKPRM/1 ->b
>   9              <$> const(AV ) s ->a
>                      ^^^^^^^^^^
> 
> So the docs are correct, then.
> 
> But I would have needed heavy emphasis on the word *array* 
> to get the point.  Whenever I see something like "returns 
> an array of values", I do an automatic s/array/list/.
> 
> And the perlop here [5.8] actually says "an list of values", 
> so maybe I'm not the only one doing auto-translation.  :-)

The 5.8 doc is definitely at odds with the implementation.  I think
the doc is right.  The behavior of "\ (1 .. 3, 5 .. 9)" certainly comes
as a surprise.

Anno


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

Date: 20 Mar 2003 08:53:49 -0800
From: m.browning@plymouth.ac.uk (M Browning)
Subject: Re: Can't access array element in Class::Struct structure
Message-Id: <eddc4731.0303200853.5a8884ca@posting.google.com>

carltonbrown@hotmail.com (Carlton Brown) wrote in message news:<aa611a32.0303192222.189fd5e2@posting.google.com>...
> tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnb7icnv.56m.tadmc@magna.augustmail.com>...
> > 
> > On Linux (RH 7.2) it works with perl 5.8.0, but fails the same way
> > as yours with 5.6.1.
> 
> A thousand thanks.  Now I know I'm not crazy.  It's puzzling
> considering this edition of the Camel book was released before 5.8.0,
> but that's a mystery for the ages.
> 
> If anyone can tell me the proper technique in 5.6.1, I'd be grateful. 
> Implementing 5.8.0 soon is unlikely for us.
> 

I've noticed this before but not given it much thought.  If I run your
code but put `$' instead of `@' for the array reference it works fine
on Perl 5.6.1 (Debian 3).

Of course, an array *reference* would be prefixed by a dollar so it
kind of makes sense, although it is contrary to the man page.  I guess
this is an implementation bug that has been ironed out.

> OR, if there's a better way to implement complex data structures, I'd
> love to hear it.

I find Class::Struct counter-productive for all but the most trivial
implementations (subjective). A `better-way' is to bless a data
structure into a package with your own constructor.

Of course, you won't get all the get/sets made for you automatically
but you could auto-create the easy ones with $AUTOLOAD then provide
methods for the more complex bits.

[MB]


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

Date: Thu, 20 Mar 2003 15:40:41 +0100
From: "Steffen Beyer" <Steffen.Beyer@de.bosch.com>
Subject: Re: Date Calculation
Message-Id: <b5cjt9$2fc$1@ns2.fe.internet.bosch.com>

This is a multi-part message in MIME format.

------=_NextPart_000_000D_01C2EEF7.0FE4A250
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

"Dan Rabb" <google@rabb.org> wrote in message news:d685454c.0303190823.214019a7@posting.google.com...
> [...]
> Any guidance, references to documentation, examples, etc. would be
> very much appreciated.  Thank you in advance.
> Dan Rabb
> 
> ---snip---
> print "Enter the date [YYYYMMDD] you wish to search for.\n" ;
> $SEARCHDATE = <STDIN>;
>       chomp ($SEARCHDATE);
> 
> $DAYBEFORE              = $SEARCHDATE - 1;
> $DAYAFTER               = $SEARCHDATE + 1;
> 
> print "The date entered was: $SEARCHDATE\n";
> print "The date before was: $DAYBEFORE\n";
> print "The date after will be: $DAYAFTER\n";
> ---snip---
> Below are the results I mentioned:
> ---snip---
> Enter the date [YYYYMMDD] you wish to search for.
> 20030301
> The date entered was: 20030301
> The date before was: 20030300
> The date after will be: 20030302
> 
> Enter the date [YYYYMMDD] you wish to search for.
> 20030131
> The date entered was: 20030131
> The date before was: 20030130
> The date after will be: 20030132
> ---snip---

See attachment for a solution.
Hope this helps.

Cheers,
Steffen Beyer

------=_NextPart_000_000D_01C2EEF7.0FE4A250
Content-Type: application/octet-stream;
	name="match.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="match.pl"

#!perl

use Date::Calc qw(:all);
# or:
#use Date::Pcalc qw(:all);
# (doesn't need a C compiler to build but is not the latest version)

while (1)
{
    print "Enter the date [YYYYMMDD] you wish to search for:\n";
    $date = <STDIN>;
    last if ((@date = $date =~ /\b(\d{4})(\d{2})(\d{2})\b/) and check_date(@date));
    print "Invalid date. Please try again.\n";
}
@before = Add_Delta_Days(@date,-1);
@after  = Add_Delta_Days(@date,+1);

$search_pattern = sprintf("%04d%02d%02d", @before) . '|' .
                  sprintf("%04d%02d%02d", @date)   . '|' .
                  sprintf("%04d%02d%02d", @after);

# now cycle through all file names:

foreach $file (qw(file20030320.txt)) # just an example!
{
    if ($file =~ /$search_pattern/)
    {
        # found a file!
        print "File '$file' matched '$search_pattern'!\n";
    }
}

------=_NextPart_000_000D_01C2EEF7.0FE4A250--



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

Date: Thu, 20 Mar 2003 12:35:51 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: doubts on \n
Message-Id: <3E79FBF7.188C2A85@earthlink.net>

Xavier Noria wrote:
> 
> After reading perlport I have yet some doubts about \n. I think my
> basic doubt is about the exact points where the conversion between
> logical and real newlines is done, but I have a little mess in my mind
> so I'll just ask some related questions instead, and see if I get the
> picture.
> 
> Assuming binmode off:
> 
> * Is length("\n") == 1 true in all platforms?

This is true regardless of binmode.

> * Is (default) $/ eq "\n" true in all platforms?

This is true regardless of binmode.

> * When is "\n" converted to "\015\012" under Windows?

When you print it to a filehandle which has not been binmode()ed.

(And it's only "\015\012" in the outputed file, not within the perl
program).

> * Is
> 
>      $whole_file = do { local $/; <FH> };
>      $whole_file =~ s/\n//g;
> 
>   a portable way to delete newlines provided the newlines in the file
>   under FH are the ones in that platform?

If FH has not been binmode()d, then yes.

> * If a script is running under Linux could the script know somehow it
>   is reading a text file from, say, a fat32 partition?

I'm not sure.  How would you do it *without* perl?

>   Does "portability" always imply the files being processed have the
>   conventions of the system reported by $^O?

A perl script is portable if it works properly on all platforms.

Generally, this means using binmode() on binary files, and not using
binmode() on files containing text.

And if you use any characters outside of the range of the 'latin-1'
encoding, you specify what the encoding is.  [If it's text or code in
your program, then 'use encoding qw(...)'.  If it's a filehandle with
non-latin1 chars, then 'binmode(FH, ":encoding(...)");']

> I am sorry I cannot think of a more concrete question that I knew in
> advance it would answer all that.

I have a question for you now -- what is it that you're trying to do?

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Thu, 20 Mar 2003 10:38:48 -0600
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: doubts on \n
Message-Id: <b5cqqq$s762@onews.collins.rockwell.com>

On 3/20/2003 5:11 AM, Xavier Noria wrote:
> 
> After reading perlport I have yet some doubts about \n. I think my
> basic doubt is about the exact points where the conversion between
> logical and real newlines is done, but I have a little mess in my
> mind so I'll just ask some related questions instead, and see if I
> get the picture.
> 
> Assuming binmode off:
> 
> * Is length("\n") == 1 true in all platforms?

Yes; within Perl \n is \012, regardless of platform.

> * Is (default) $/ eq "\n" true in all platforms?

Yes.

> * When is "\n" converted to "\015\012" under Windows?

During the low-level reads and writes. That is, if you say

   $line = <FH>;

\015\012 will be converted to \012 *before* the string is stored in $line.

Likewise, when you say

   print "text\n";

The \n (which is really a \012) is converted to \015\012 just before the
data is actually printed.

> * Is
> 
>     $whole_file = do { local $/; <FH> };
>     $whole_file =~ s/\n//g;
> 
> a portable way to delete newlines provided the newlines in the file
> under FH are the ones in that platform?

Uh, I suppose so, though the typical method for removing newlines is
chomp().

> * If a script is running under Linux could the script know somehow it
>   is reading a text file from, say, a fat32 partition?

There's no built-in method. Besides, just because a file resides on a
FAT32 (or NTFS, or EXT, or...) partition doesn't mean it's in a
particular format. It's quite possible to have a DOS file on a *nix
partition or vice-versa.

If you want to detect the file type, your probably best off to use -T
(to determine if something is a text file at all) then do a sysread of
the first couple hundred bytes and look for line-end patterns in the data.

> Does "portability" always imply the files being processed have the
> conventions of the system reported by $^O?

Portability of what? The code? The files? I don't understand your
question. A Perl program will normally read and write files in the
platform format. For some applications (networking comes to mind) you
may want to always use a specific sequence instead.

-mjc



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

Date: Thu, 20 Mar 2003 18:07:00 +0000 (UTC)
From: Xavier Noria <fxn@hashref.com>
Subject: Re: doubts on \n
Message-Id: <b5d004$goo$1@news.ya.com>

In article <b5cqqq$s762@onews.collins.rockwell.com>, Michael Carman wrote:

:> * Is length("\n") == 1 true in all platforms?
: 
: Yes; within Perl \n is \012, regardless of platform.
: 
:> * Is (default) $/ eq "\n" true in all platforms?
: 
: Yes.

OK, so this sentence from perlport:

  A common misconception in socket programming is that "\n" eq "\012"
  everywhere.
  
refers to "\n" *after* the low-level print.

If "\n" eq "\012" is true in all platforms (as strings, no I/O), how does
the I/O system know the first might need translation but not the second?
Does the underlying data managed by the interpreter has a flag in that
character that marks it as logical newline?

:> * When is "\n" converted to "\015\012" under Windows?
: 
: During the low-level reads and writes. That is, if you say
: 
:    $line = <FH>;
: 
: \015\012 will be converted to \012 *before* the string is stored in $line.

Then, why does perlport say chop() will just cut half of the end-of-line on
DOSish systems in a typical while (<FH>) loop? If we got always a \012 at
the end of the line chop() should be safe in that sense, shouldn't it?

Thank you very much!

-- fxn


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

Date: Thu, 20 Mar 2003 18:15:36 +0000 (UTC)
From: Xavier Noria <fxn@hashref.com>
Subject: Re: doubts on \n
Message-Id: <b5d0g8$goo$2@news.ya.com>

In article <3E79FBF7.188C2A85@earthlink.net>, Benjamin Goldberg wrote:

: (And it's only "\015\012" in the outputed file, not within the perl
: program).

That's very clarifying.

: A perl script is portable if it works properly on all platforms.
: 
: Generally, this means using binmode() on binary files, and not using
: binmode() on files containing text.

Alright, so

    ++$nlines while <>;
    print $nlines;
    
would be a portable line-counter, because portable implies it's supposed to
work just with files which follow the conventions of the platform where it
runs, regardless of foreign filesystems mounted.

: I have a question for you now -- what is it that you're trying to do?

I am not programming nothing diretly related to that, just trying to
understand that corner of Perl well.

Thank you very much!

-- fxn


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

Date: Thu, 20 Mar 2003 13:31:54 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: doubts on \n
Message-Id: <3E7A091A.EA4259EB@earthlink.net>

Michael Carman wrote:
> 
> On 3/20/2003 5:11 AM, Xavier Noria wrote:
> >
> > After reading perlport I have yet some doubts about \n. I think my
> > basic doubt is about the exact points where the conversion between
> > logical and real newlines is done, but I have a little mess in my
> > mind so I'll just ask some related questions instead, and see if I
> > get the picture.
> >
> > Assuming binmode off:
> >
> > * Is length("\n") == 1 true in all platforms?
> 
> Yes; within Perl \n is \012, regardless of platform.

No.  On macintosh, \n is \010.  On Mac, no newline translation is done
when printing or reading, regardless of binmode.

However, the length of "\n" is still 1.

[snip]
> > * Is
> >
> >     $whole_file = do { local $/; <FH> };
> >     $whole_file =~ s/\n//g;
> >
> > a portable way to delete newlines provided the newlines in the file
> > under FH are the ones in that platform?
> 
> Uh, I suppose so, though the typical method for removing newlines is
> chomp().

That's true when you're reading a line at a time, or when slurping into
an array (you then chomp the array).

Here, though, the OP is slurping the whole file into a single string.

PS:

   $whole_file =~ tr/\n//d;

Would be faster than s/\n//g.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: 20 Mar 2003 18:54:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: doubts on \n
Message-Id: <b5d2oi$9fo$1@mamenchi.zrz.TU-Berlin.DE>

Xavier Noria  <fxn@hashref.com> wrote in comp.lang.perl.misc:
> In article <b5cqqq$s762@onews.collins.rockwell.com>, Michael Carman wrote:
> 
> :> * Is length("\n") == 1 true in all platforms?
> : 
> : Yes; within Perl \n is \012, regardless of platform.
> : 
> :> * Is (default) $/ eq "\n" true in all platforms?
> : 
> : Yes.
> 
> OK, so this sentence from perlport:
> 
>   A common misconception in socket programming is that "\n" eq "\012"
>   everywhere.
>   
> refers to "\n" *after* the low-level print.

No, it's a way of saying that not every receiver expects lines to be
separated the way Perl IO separates them on the given system.  Print
produces whatever is customary on the system it is running on.  On a
socket this *could* be wrong.

> If "\n" eq "\012" is true in all platforms (as strings, no I/O), how does
> the I/O system know the first might need translation but not the second?
> Does the underlying data managed by the interpreter has a flag in that
> character that marks it as logical newline?

No need for that.  All "\n"s are equal and are treated equally.

> :> * When is "\n" converted to "\015\012" under Windows?
> : 
> : During the low-level reads and writes. That is, if you say
> : 
> :    $line = <FH>;
> : 
> : \015\012 will be converted to \012 *before* the string is stored in $line.
> 
> Then, why does perlport say chop() will just cut half of the end-of-line on
> DOSish systems in a typical while (<FH>) loop? If we got always a \012 at
> the end of the line chop() should be safe in that sense, shouldn't it?

I'm afraid perlport mis-presents the situation in which the problem
(chop()ing half an end-of-line) occurs.  I have no personal experience
with Perl on Windows, so I'm on thin ice here, but if this thread hasn't
been wildly wrong, this doesn't occur with native files on a Windows
system (nor with native files on any system).

It does occur on a Unix system when DOSish files are read which have
carelessly been transfered in their original format, but then chomp()
isn't the solution either (unless you explicitly set $/).

Anno


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

Date: Thu, 20 Mar 2003 19:19:34 +0100
From: "Pascal Zerwetz" <pzerwetz@yaccom.com>
Subject: getOpenFile with -initialdir
Message-Id: <b5d0nk$24l6$1@biggoron.nerim.net>

Hello
First many thanks to Christian Winter!
I am using perl/Tk in Cygwin, on W2k.
When I open the getOpenFile dialog, even with use of Cwd and -initialdir =
Cwd,
the starting directory is the latest used.
Can anyone tell me how can I force the initialdir, please ?
Thank you.
Pascal.




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

Date: Thu, 20 Mar 2003 14:44:33 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How can I....?
Message-Id: <ltkea.40939$Ad6.31776@nwrddc01.gnilink.net>

Cyber Scorpion wrote:
> I want to compare 2 strings in case in-sensitive mode, but the strings
> contain cyrillic characters (ascii code > 127 and < 255) and the
> standart way does not work, i.e. the following code:
>
> if ($sdata =~ /$rdata/i)

That's not the standard way to begin with. First of all using REs to compare
two strings is like using a shotgun to kill a fly. A fly swatter would be a
more appropriate tool. And second what if $rdata contains characters which
are special in REs? Let's say $rdata is the string '.*'?

If you want to compare two strings then you should use the string comparison
operator.
And if you want to compare them with ignore case then just convert both into
a normal form, e.g. all upper case:
    if (uc($data) eq uc($rdata))

jue




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

Date: Thu, 20 Mar 2003 12:42:27 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: how to check file size (very large! > 2GB) using Perl
Message-Id: <3E79FD83.1C1B88AE@earthlink.net>

Yong Liu wrote:
> 
> Hi,
> 
> I have got a problem using either -s $filename or stat $filename to
> get the correct information about the file size. Here is what I got:
> 
> output of -s $filename
> File Size: -1522664308 bytes
[]
> The actual file size should be:2772302988 bytes (using ls -al)
> 
> So how should I check the file size for this kind of large file using
> Perl?

Try this:
   my $size = -s $filename;
   $size &= 0xFFFFFFFF if defined($size) && $size < 0;

Or, recompile perl with large file support enabled.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: 20 Mar 2003 09:17:21 -0800
From: clearguy02@yahoo.com (John Smith)
Subject: Re: How to include data stamps in a script??
Message-Id: <500f84f3.0303200917.1a140710@posting.google.com>

"Tore Aursand" <tore@aursand.no> wrote in message news:<pan.2003.03.20.03.29.38.971529@aursand.no>...
> On Wed, 19 Mar 2003 14:18:49 -0800, John Smith wrote:
> > I am writing a perl script that runs several times a day. Every time it
> > runs, it needs to give an output file like below:
> > 
> > test1_links_03182003[1].html when the script is run first time; (where
> > 03182003 is today's date and [1] reperesents that the script is run for
> > the first time today)
> > test1_links_03182003[2].html when the script is run second time;
> > test1_links_03182003[3].html when the script is run third time;
> > test1_links_03182003[4].html when the script is run fourth time;
> 
> In other words, you want to generate an unique filename each time.  Let's
> have a look at that, but first:
> 
> Why do you want to use 'MMDDYYYY' as date format?  Stick with 'YYYYMMDD'
> is my suggestion.
> 
> To create the unique filename, follow this thinking:
> 
>   my $count = 1;
>   while ( -e $filename . '_' . $date . '[' . $count . ']' . '.html' ) {
>       $count++;
>   }
> 
> Not so hard.  To parse your filename (ie. 'test1_links.html' in your
> example), you could use File::Basename to extract path, filename and
> suffix.
> 
> For the date part, you'll get going with 'localtime()'.
--------------

Thanks Tore,

Yea,  I can use YYYYMMDD format. I need to get a file,
test1_links_20030320[1].html, when I run the script for the first
time. When I run the scipt second time on the same day, I need to get
another file, test1_links_20030320[2].html and so on..

Would you pl. elaborate your explanation (by writing the code)?

Thansk,
John


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

Date: Thu, 20 Mar 2003 16:17:23 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Need a little help with a short script
Message-Id: <pan.2003.03.20.07.25.27.814016@aursand.no>

On Wed, 19 Mar 2003 22:31:17 -0800, HKVandal wrote:

> while(defined($file=readdir(DIR))){
> $old_file=$file;
> if($file=~/.*\.(.*)/){
> $currext=$1;
> if($currext=$old){
> $file=~/(.*)\..*/;
> $currfile=$1;
> $new_file=$currfile . "\." . $new;
> rename ($old_file, $new_file) or die "$!";
> }
> }
> }

Never heard about indentation, eh? :)  Anyway.  You shouldn't do, or try
to do, something which has already been done so much, much better.

There's a module called File::Basename which extracts the path, filename
and suffix (ie. extension) of any file on any (...) system.  You should
use that one instead;

  #!/usr/bin/perl
  #
  use strict;
  use warnings;
  use File::Basename qw( fileparse );

  my $old_filename = 'c:\Program Files\test.exe';
  my ( $path, $filename, $suffix ) = fileparse( $old_filename );
  my $new_filename = $path . $filename . '.bak';

> I get the following error when I run it
> Permission denied at c:\docs\ext.pl line 16, <STDIN> line 3.

Your system's permission settings has nothing to do with Perl.


-- 
Tore Aursand


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

Date: Thu, 20 Mar 2003 14:43:38 GMT
From: "David" <perl-dvd@darklaser.com>
Subject: Re: Open file and print out contents from array
Message-Id: <uskea.12$lt.3273@news-west.eli.net>

"Jacques Veldhuijzen" <veld@interparts-cp.nl> wrote in message
news:cb594a0f.0303192234.2a17e526@posting.google.com...
> I did create the following script detail
>
> open (IN, "$text_url");
> @lines = <IN>; # Slurp file into array
> print MAIL @lines;
>         close(IN);
>
> My intention is to open a file with text to be included into a e-mail
> message to be sent to a recipient.
>
> When i use
> print MAIL "'$text_url'\n";
> the value of this variable appears in the e-mail correctly.

That does not necissarily mean it opened the file properly

> The instruction
>         print MAIL @lines;
> has no effect at all.
>
> How can i make this work easily


First of all, you should probably specify that you want the file
contents for read, and second you should put a warn or die on it incase
it fails to open, something like this:

open (IN, "<$text_url") or die "Failed to open $text_url because $!";

Run the script again, and see if it tells you it failed to open the file
(should print to the command line or your error log).

Regards,
David
perl -e'print for map chr$_+1,"111100113107044099117099132"=~/(.{3})/g'





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

Date: 20 Mar 2003 06:52:09 -0800
From: veld@interparts-cp.nl (Jacques Veldhuijzen)
Subject: Re: Open file and print out contents from array
Message-Id: <cb594a0f.0303200652.26174550@posting.google.com>

"Jürgen Exner" <jurgenex@hotmail.com> wrote in message news:<JPdea.61022$iq1.22538@nwrddc02.gnilink.net>...
> Jacques Veldhuijzen wrote:
> > I did create the following script detail
> >
> > open (IN, "$text_url");
> 
> Useless use of quotes.
> Missing
>     or die "Cannot open $text_url because $!\n"
> 
I did change this in the following instruction:

open(IN,$text_url) or die "Cannot open $text_url because $!\n"; 

This open instruction is NOT working, but i do not see an error  message.
print MAIL instructions right after the open instruction are NOT executed.

That is why i do think the open statement is causing the problem

The question is how come


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

Date: Thu, 20 Mar 2003 09:16:54 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Open file and print out contents from array
Message-Id: <slrnb7jmr6.6q9.tadmc@magna.augustmail.com>

Jacques Veldhuijzen <veld@interparts-cp.nl> wrote:

> open(IN,$text_url) or die "Cannot open $text_url because $!\n"; 
> 
> This open instruction is NOT working, but i do not see an error  message.


What environment are you running this program under?

If this is a stealth CGI problem, then shame on you, and

   perldoc -q CGI

      How can I get better error messages from a CGI program?


Run it from the command line.


> print MAIL instructions right after the open instruction are NOT executed.


It is not possible to know that, so how do you know that?

All you can know is that they do not make output, it may be that
they _are_ executing.


> That is why i do think the open statement is causing the problem
> 
> The question is how come


The question is how come you are not seeing the error message.


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


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

Date: Thu, 20 Mar 2003 15:11:02 +0000 (UTC)
From: Tore Linde Gustavsen <torelg@start.no>
Subject: Re: Reverse assignment operator
Message-Id: <slrnb7jmh0.3hk.torelg@localhost.localdomain>

Thanks to both Tassilo and Bernard for answers. 

I've seen modules for filtering source on CPAN, but thought they were
only used for encrypting or obfuscating code. It didn't strike me that
they could be used for emulating userdefined operators.

I searched a bit with google and couldn't find anything suggesting
userdefined operators would be a new feature of perl6.  Oh, well.

-- 
Tore Gustavsen,
torelg@start.no 


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

Date: 20 Mar 2003 15:26:50 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Reverse assignment operator
Message-Id: <b5cmjq$629$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Tore Linde Gustavsen:

> Thanks to both Tassilo and Bernard for answers. 
> 
> I've seen modules for filtering source on CPAN, but thought they were
> only used for encrypting or obfuscating code. It didn't strike me that
> they could be used for emulating userdefined operators.

It can be used for anything. Given a powerful parser, you could thusly
preprocess Python into Perl code (theoretically).

> I searched a bit with google and couldn't find anything suggesting
> userdefined operators would be a new feature of perl6.  Oh, well.

As far as I know Perl6 will allow to define your own operators. 

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Thu, 20 Mar 2003 12:24:50 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Reverse assignment operator
Message-Id: <3E79F962.60A23F0A@earthlink.net>

Tore Linde Gustavsen wrote:
> 
> Thanks to both Tassilo and Bernard for answers.
> 
> I've seen modules for filtering source on CPAN, but thought they were
> only used for encrypting or obfuscating code. It didn't strike me that
> they could be used for emulating userdefined operators.
> 
> I searched a bit with google and couldn't find anything suggesting
> userdefined operators would be a new feature of perl6.  Oh, well.

Read the perl6 Apocalypses.

In Apocalypse 3, Larry says that user defined operators will exist (but
doesn't say what the syntax will be).

In Apocalypse 5, page 11, Larry says that you can define operators by
sticking any of "prefix:" "infix:", "postfix:", or "circumfix:" on the
fronts of their names (yes, those are single, not double colons).

They can be any subroutine type -- normal subs, macros, multimethods,
etc., their scope can be lexical, package, or global.

   # define a factorial operator globally.
   sub *postfix:! (Int $x) { return factorial($x) }
   print 5!, "\n"; # prints 120

   # define Pascal comments within this lexical scope:
   my macro circumfix:(**) () is parsed(/.*?/) { "" }

   # define a global ± operator for this pacakge.
   sub infix:± (int $a, int $b) {
      return Quantum::Superpositions::all(
         ($a - $b)..($a + $b),
      );
   }

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Wed, 19 Mar 2003 16:44:32 GMT
From: Steve Grazzini <grazz@nyc.rr.com>
Subject: Re: running a script on multiple files in a directory
Message-Id: <Q71ea.1133$DQ.891018@twister.nyc.rr.com>

Tore Aursand <tore@aursand.no> wrote:
> On Wed, 19 Mar 2003 14:56:11 +0000, Ahmad.J.Reeves wrote:
> 
>> # slurp in whole file and flatten
>> open( FILE, "< $filename" ) or die "Error: can\'t open $filename\n";
>> @lines = <FILE>;
>> close( FILE ) or die "Error: can\'t close $filename\n";
>> ( $text = "@lines" ) =~ s/\n//g;
> 
> Hmm.  I prefer this method;
> 
>   open( FILE, '<' . $filename ) or die "Can't open file: $!\n";
>   my $text = '';
>   {
>       local $/ = undef;
>       $text = <FILE>;
>   }
>   close( FILE );

That could still be a bit more direct [IMO]

    my $text = do {
      local $/;
      open my $fh, $filename or die "open: $filename: $!";
      <$fh>
    };

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'


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

Date: Thu, 20 Mar 2003 13:49:25 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Socket Problem In Perl
Message-Id: <3E7A0D35.A46F5AA@earthlink.net>

Ryan Ritten wrote:
> 
> hello,
> 
> I wrote a little client/server in perl using sockets.  Everything
> works fine if the client exits normally ... the server notices that
> the socket is done and closes it.  But if the client dies abnormally
> (ie. computer freezes... etc) the server doesn't notice that the
> client is gone and keeps the socket open...

If the client program (but not the client machine) dies, then the OS
(the tcp stack, whatever) should send an appropriate low-level tcp
packet to terminate the connection.

If the client machine (or, for ease of testing, the the client's
physical network connection or even it's network inteface) goes down,
then there's nothing to tell your server program that the client is
dead.

In *some* ways, this is a good thing -- suppose that you've a DSL or
cable connection going into your USB port, and someone trips over the
wire, pulling the plug out of the computer -- if you quickly plug the
wire back in, then your connection is still alive!  Or, if a router
between the client and server goes down for a few minutes and reboots,
the network connection is a long-term one (meant to be kept alive for
hours, or 'forever') ... your connection should survive the lapse.

> am I doing something wrong?  Is this was it supposed to happen or is
> there a quick fix for it.  I'd paste my code here but it's part of a
> game I've made and is huge.

This is supposed to happen, *and* there is a quick fix for it.

   $socket->sockopt( SO_KEEPALIVE, 1 );

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Thu, 20 Mar 2003 11:45:53 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Text::ParseWords or Text::CSV
Message-Id: <3E79F041.1952E365@earthlink.net>

david wrote:
> 
> Does anyone have experience with either of these two modules? Im
> trying to figure out how to parse a comma delimited file, but the
> problem is certain fields also have commas so when the file is
> exported to text format, of course it now looks like it has more
> fields. I want to remove the comma's from the fields that have them:
> 
> dlepage,engineer,mn,"infrastrucuture",6-5-02
> aidan,support,va,"infrastructure,engineering", 3-1-96
> 
> I put quotes around the actual 'field 3', but the actual file I want
> to work on does NOT have the quotes:
> 
> dlepage,engineer,mn,infrastrucuture,6-5-02
> aidan,support,va,infrastructure,engineering, 3-1-96
> 
> i.e.
> field0=aidan
> field1=support
> field2=va
> field3=infrastructure,engineering
> field4=3-1-96

while( <IN> ) {
   my ($field0, $field1, $field2, @fields34) = split /,/, $_, -1;
   my $field4 = pop @fields34;
   my $field3 = join(",", @fields34);
}

[untested]

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Thu, 20 Mar 2003 12:55:53 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: UDP Comms Problem
Message-Id: <3E7A00A9.CFE2DF24@earthlink.net>

Al wrote:
[snip]
> $iaddr = inet_aton(192.168.122.188);    $port = 4399;

Under perl 5.6.1 and later, this is actually equivialnt to:

   $iaddr = inet_aton(v192.168.122.188);
Or:
   $iaddr = inet_aton(pack 'U*', 192, 169, 122, 199);

Under earlier perls, it is eqivilant to:
   $iaddr = inet_aton(192168122188);

In either case, I seriously doubt it is what you want.

Anyway, I would suggest you change your code to:

use strict;
use warnings;
use IO::Socket;

my $sock = IO::Socket::INET->new(
   Proto => "udp",
   PeerPort => 4399,
   PeerAddr => "192.168.122.188",
) or die "Socket creation failed: $@";

my $reply = "";

while( 1 ) {
   $sock->recv( my($buffer), 1000 ) or die "recv failed: $!";
   print $buffer;
   next unless $buffer =~ /^N/;
   substr( $buffer, 0, 4 ) = "";
   $reply .= $buffer;
   $sock->send( $reply ) or die "send failed: $!";
}

[untested]

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

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


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