[24709] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6866 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 14 14:06:26 2004

Date: Sat, 14 Aug 2004 11: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)

Perl-Users Digest           Sat, 14 Aug 2004     Volume: 10 Number: 6866

Today's topics:
    Re: Counting text area <andrewpalmer@email.com>
    Re: Counting text area <noreply@gunnar.cc>
    Re: Counting text area <lv@aol.com>
    Re: Counting text area (Anno Siegel)
    Re: Counting text area (Anno Siegel)
    Re: Counting text area <noreply@gunnar.cc>
    Re: Counting text area (Anno Siegel)
    Re: Counting text area <noreply@gunnar.cc>
    Re: data comprised of regexs (while loop weirdness) <usenet@morrow.me.uk>
        Emacs modules for Perl programming (Jari Aalto+mail.perl)
        Getting position from unpack (was: "join on space inste (J. Romano)
    Re: Good way to un-chomp an array <tadmc@augustmail.com>
    Re: Good way to un-chomp an array <dug@plusthree.com>
    Re: Good way to un-chomp an array <postmaster@castleamber.com>
    Re: Good way to un-chomp an array (Randal L. Schwartz)
    Re: Good way to un-chomp an array <tadmc@augustmail.com>
    Re: Good way to un-chomp an array <matthew.garrish@sympatico.ca>
    Re: Good way to un-chomp an array <jurgenex@hotmail.com>
    Re: Good way to un-chomp an array 510046470588-0001@t-online.de
    Re: howto convert a *nix DB_File to windows? <Paul.Marquess@btinternet.com>
    Re: howto convert a *nix DB_File to windows? (dan baker)
    Re: howto convert a *nix DB_File to windows? <noreply@gunnar.cc>
    Re: howto convert a *nix DB_File to windows? 580046470588-0001@t-online.de
    Re: My own handy Pocket Reference notes (please share y <usenet@morrow.me.uk>
    Re: My own handy Pocket Reference notes (please share y <nobull@mail.com>
    Re: noob question: use File::Copy;      <jeff@spamalanadingong.com>
    Re: noob question: use File::Copy;      <tadmc@augustmail.com>
    Re: noob question: use File::Copy;  <jeff@spamalanadingong.com>
    Re: testing without shell access <usenet@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 13 Aug 2004 17:44:20 -0500
From: "Andrew Palmer" <andrewpalmer@email.com>
Subject: Re: Counting text area
Message-Id: <jsbTc.13185$5s3.10985@fe40.usenetserver.com>


"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:2o4jbpF6iahcU1@uni-berlin.de...
> Joe Smith wrote:
> > Gunnar Hjalmarsson wrote:
> >>
> >>     my $count = 0;
> >>     $count ++ for split /\n/, $in{packageID};
> >
> > my $count = () = split /\n/,$in{packageID};
>
>      my %in = ( packageID => "one\ntwo\nthree" );
>
>      my $count = () = split /\n/, $in{packageID};
>      print "$count\n";
>
>      $count = 0;
>      $count ++ for split /\n/, $in{packageID};
>      print "$count\n";

     my $count = split /\n/, $in{packageID};
     print "$count\n";

>
> Outputs:
> 1
> 3

3

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





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

Date: Sat, 14 Aug 2004 00:54:29 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Counting text area
Message-Id: <2o4vc2F7172nU1@uni-berlin.de>

Andrew Palmer wrote:
> Gunnar Hjalmarsson wrote:
>> Joe Smith wrote:
>>> Gunnar Hjalmarsson wrote:
>>>>
>>>>     my $count = 0;
>>>>     $count ++ for split /\n/, $in{packageID};
>>>
>>> my $count = () = split /\n/,$in{packageID};
>>
>>     my %in = ( packageID => "one\ntwo\nthree" );
>>
>>     my $count = () = split /\n/, $in{packageID};
>>     print "$count\n";
>>
>>     $count = 0;
>>     $count ++ for split /\n/, $in{packageID};
>>     print "$count\n";
> 
>      my $count = split /\n/, $in{packageID};
>      print "$count\n";
> 
>> Outputs:
>> 1
>> 3
> 
> 3

Hey, did you read the docs or something?

Thanks! ;-)

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


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

Date: Fri, 13 Aug 2004 21:54:02 -0500
From: l v <lv@aol.com>
Subject: Re: Counting text area
Message-Id: <411d7ebf$1_2@corp.newsgroups.com>

Davidd Sargent wrote:
> My Code
> Sorry I'm a beginner.
> 
> $tempvar = $in{'packageID'};
> $line = "\n";
> @newtextareaarray = split($tempvar,$line);
> $count ="0";
> foreach $line (@newtextareaarray) {
> $count++;
> 
> }
> 
> 
> print qq|Here : $count|;
> 
> 
> Thanks
> 
> Dave
> 

You could use tr///

$tempvar = $in{'packageID'};
$count = $tempvar =~ tr/\n/\n/;

print qq|Here : $count|;

Len


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 100,000 Newsgroups - 19 Different Servers! =-----


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

Date: 14 Aug 2004 07:37:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Counting text area
Message-Id: <cfkfgm$a1q$1@mamenchi.zrz.TU-Berlin.DE>

Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> Joe Smith wrote:
> > Gunnar Hjalmarsson wrote:
> >> 
> >>     my $count = 0;
> >>     $count ++ for split /\n/, $in{packageID};
> > 
> > my $count = () = split /\n/,$in{packageID};
> 
>      my %in = ( packageID => "one\ntwo\nthree" );
> 
>      my $count = () = split /\n/, $in{packageID};
>      print "$count\n";
> 
>      $count = 0;
>      $count ++ for split /\n/, $in{packageID};
>      print "$count\n";
> 
> Outputs:
> 1
> 3

That can be fixed:

    my $count = () = split /\n/,$in{packageID}, -1;

Anno


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

Date: 14 Aug 2004 07:45:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Counting text area
Message-Id: <cfkfuc$a1q$2@mamenchi.zrz.TU-Berlin.DE>

Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> Andrew Palmer wrote:
> > Gunnar Hjalmarsson wrote:
> >> Joe Smith wrote:
> >>> Gunnar Hjalmarsson wrote:
> >>>>
> >>>>     my $count = 0;
> >>>>     $count ++ for split /\n/, $in{packageID};
> >>>
> >>> my $count = () = split /\n/,$in{packageID};
> >>
> >>     my %in = ( packageID => "one\ntwo\nthree" );
> >>
> >>     my $count = () = split /\n/, $in{packageID};
> >>     print "$count\n";
> >>
> >>     $count = 0;
> >>     $count ++ for split /\n/, $in{packageID};
> >>     print "$count\n";
> > 
> >      my $count = split /\n/, $in{packageID};
> >      print "$count\n";
> > 
> >> Outputs:
> >> 1
> >> 3
> > 
> > 3
> 
> Hey, did you read the docs or something?
> 
> Thanks! ;-)

Have you run it under warnings?  "Use of implicit split to @_ is
deprecated...".

This warning can not be suppressed by "no warnings 'deprecated'", nor
by any other warnings category I've tried.  So this would end up as
something like

    my $count = do { no warnings; split /\n/, $in{packageID} };

which is not very nice.

Facit:  split() is far too clever for its own good.  Ilya has recently
pointed this out too.

Anno



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

Date: Sat, 14 Aug 2004 15:04:55 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Counting text area
Message-Id: <2o6h7rF76bp0U1@uni-berlin.de>

Anno Siegel wrote:
> Gunnar Hjalmarsson wrote:
>> Joe Smith wrote:
>>> Gunnar Hjalmarsson wrote:
>>>>
>>>>     my $count = 0;
>>>>     $count ++ for split /\n/, $in{packageID};
>>>
>>> my $count = () = split /\n/,$in{packageID};
>>
>>     my %in = ( packageID => "one\ntwo\nthree" );
>>
>>     my $count = () = split /\n/, $in{packageID};
>>     print "$count\n";
>>
>>     $count = 0;
>>     $count ++ for split /\n/, $in{packageID};
>>     print "$count\n";
>>
>> Outputs:
>> 1
>> 3
> 
> That can be fixed:
> 
>     my $count = () = split /\n/,$in{packageID}, -1;

Is it possible to figure out from the docs that LIMIT makes a 
difference in that respect?

Wonder why I suggested the

     $count ++ for split /\n/, $in{packageID};

solution? ;-)

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


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

Date: 14 Aug 2004 14:06:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Counting text area
Message-Id: <cfl6a0$lv6$1@mamenchi.zrz.TU-Berlin.DE>

Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > Gunnar Hjalmarsson wrote:
> >> Joe Smith wrote:
> >>> Gunnar Hjalmarsson wrote:
> >>>>
> >>>>     my $count = 0;
> >>>>     $count ++ for split /\n/, $in{packageID};
> >>>
> >>> my $count = () = split /\n/,$in{packageID};
> >>
> >>     my %in = ( packageID => "one\ntwo\nthree" );
> >>
> >>     my $count = () = split /\n/, $in{packageID};
> >>     print "$count\n";
> >>
> >>     $count = 0;
> >>     $count ++ for split /\n/, $in{packageID};
> >>     print "$count\n";
> >>
> >> Outputs:
> >> 1
> >> 3
> > 
> > That can be fixed:
> > 
> >     my $count = () = split /\n/,$in{packageID}, -1;
> 
> Is it possible to figure out from the docs that LIMIT makes a 
> difference in that respect?

Indirectly.  The reason that we see $count = 1 is that split in list
context figures out how many elements are expected and, if there is
a bound, assumes a LIMIT of one more than that.  (One more so that
the remainder of the string doesn't cling to the last element.)
Supplying an explicit, but ineffective, LIMIT of -1 stops that from
happening.

Actually, a LIMIT of 0 would be better because it behaves like no LIMIT
with respect to trailing empty fields.  If the string is closed with a
line feed, as when it is read from a file, that makes a difference.

Did I mention split() is too clever for its own good?

> Wonder why I suggested the
> 
>      $count ++ for split /\n/, $in{packageID};
> 
> solution? ;-)

Not at all.

    my $count = @{ [ split /\n/,$in{packageID}]};

could also be used.

Anno


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

Date: Sat, 14 Aug 2004 18:14:58 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Counting text area
Message-Id: <2o6scdF7f9aoU1@uni-berlin.de>

Anno Siegel wrote:
> Gunnar Hjalmarsson wrote:
>> Anno Siegel wrote:
>>> 
>>> That can be fixed:
>>> 
>>>     my $count = () = split /\n/,$in{packageID}, -1;
>> 
>> Is it possible to figure out from the docs that LIMIT makes a 
>> difference in that respect?
> 
> Indirectly.  The reason that we see $count = 1 is that split in
> list context figures out how many elements are expected and, if
> there is a bound, assumes a LIMIT of one more than that.  (One more
> so that the remainder of the string doesn't cling to the last
> element.) Supplying an explicit, but ineffective, LIMIT of -1 stops
> that from happening.
> 
> Actually, a LIMIT of 0 would be better because it behaves like no
> LIMIT with respect to trailing empty fields.  If the string is
> closed with a line feed, as when it is read from a file, that makes
> a difference.

Aha, thanks for the explanation.

> Did I mention split() is too clever for its own good?

Yes, you did, and unless you consider 'clever' eq 'complex', I
disagree. Such design is not cleverness to me. ;-)

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


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

Date: Fri, 13 Aug 2004 18:11:48 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: data comprised of regexs (while loop weirdness)
Message-Id: <kb9vu1-dm4.ln1@mauzo.dyndns.org>


Quoth bowsayge <bowsayge@nomail.afraid.org>:
> Scott W Gifford said to us:
> 
> [...]
> > regular expressions can contain code, so if
> > somebody can write to that file they'll have the ability to cause your
> > script to execute code of their choice.
> 
> How can this feature be disabled?

It is disabled by default in regexes created from interpolated
variables, unless you use re 'eval'. That is, either of these will
execute the code:

/(?{system 'rm -rf /'})/

{
    use re 'eval';
    my $danger = '(?{system "rm -rf /"})';
    /$danger/;
}

but this won't:

my $danger = '(?{system "rm -rf /"})';
/$danger/;

 .

Ben

-- 
   Razors pain you / Rivers are damp
   Acids stain you / And drugs cause cramp.                    [Dorothy Parker]
Guns aren't lawful / Nooses give
  Gas smells awful / You might as well live.                   ben@morrow.me.uk


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

Date: 14 Aug 2004 08:00:57 GMT
From: <jari.aalto <AT> poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1092470421@rtfm.mit.edu>

Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto A T poboxes com

Announcement: "What Emacs lisp modules can help with programming Perl"

    Preface

        Emacs is your friend if you have to do anything comcerning software
        development: It offers plug-in modules, written in Emacs lisp
        (elisp) language, that makes all your programmings wishes come
        true. Please introduce yourself to Emacs and your programming era
        will get a new light.

    Where to find Emacs/XEmacs

        o   Unix:
            http://www.gnu.org/software/emacs/emacs.html
            http://www.xemacs.org/

        o   Unix Windows port (for Unix die-hards):
            install http://www.cygwin.com/  which includes native Emacs 21.x.
            and XEmacs port

        o   Pure Native Windows port
            http://www.gnu.org/software/emacs/windows/ntemacs.html
            ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe

        o   More Emacs resources at
            http://tiny-tools.sourceforge.net/  => Emacs resource page

Emacs Perl Modules

    Cperl -- Perl programming mode

        http://www.cpan.org/modules/by-authors/id/ILYAZ/cperl-mode/
        http://math.berkeley.edu/~ilya/software/emacs/
        by Ilya Zakharevich

        CPerl is major mode for editing perl files. Forget the default
        `perl-mode' that comes with Emacs, this is much better. Comes
        standard in newest Emacs.

    TinyPerl -- Perl related utilities

        http://tiny-tools.sourceforge.net/

        If you ever wonder how to deal with Perl POD pages or how to find
        documentation from all perl manpages, this package is for you.
        Couple of keystrokes and all the documentaion is in your hands.

        o   Instant function help: See documentation of `shift', `pop'...
        o   Show Perl manual pages in *pod* buffer
        o   Grep through all Perl manpages (.pod)
        o   Follow POD references e.g. [perlre] to next pod with RETURN
        o   Coloured pod pages with `font-lock'
        o   Separate `tiperl-pod-view-mode' for jumping topics and pages
            forward and backward in *pod* buffer.

        o   Update `$VERSION' variable with YYYY.MMDD on save.
        o   Load source code into Emacs, like Devel::DProf.pm
        o   Prepare script (version numbering) and Upload it to PAUSE
        o   Generate autoload STUBS (Devel::SelfStubber) for you
            Perl Module (.pm)

    TinyIgrep -- Perl Code browsing and easy grepping

        [TinyIgrep is included in Tiny Tools Kit]

        To grep from all installed Perl modules, define database to
        TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
        how to set up dattabases for Perl5, Perl4 whatever you have
        installed

        TinyIgrep calls Igrep.el to to do the search, You can adjust
        recursive grep options, set search case sensitivity, add user grep
        options etc.

        You can find latest `igrep.el' module at
        <http://groups.google.com/groups?group=gnu.emacs.sources> The
        maintainer is Jefin Rodgers <kevinr <AT> ihs.com>.

    TinyCompile -- To Browse grep results in Emacs *compile* buffer

        TinyCompile is a minor mode for *compile* buffer from where
        you can collapse unwanted lines or shorten file URLs:

            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT

            -->

            cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
            file1:NNN: MATCHED TEXT
            file1:NNN: MATCHED TEXT

End



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

Date: 14 Aug 2004 09:28:56 -0700
From: jl_post@hotmail.com (J. Romano)
Subject: Getting position from unpack (was: "join on space instead of comma")
Message-Id: <b893f5d4.0408140828.42c5ee27@posting.google.com>

Tassilo v. Parseval wrote:

> here's one that I find useful, namely the '/' construct.
> The template preceeding the slash is used as a count
> argument for the template following the slash:

<code snipped>

> Note how this can be combined with @:
>
>     my @x = unpack '@2c/C', "\x03\x00\x01\xff\x03";
>     print "@x\n",
>     __END__
>     255

   Before that thread, I wasn't aware that I could use '@' like that
to start the position of unpacking.  Before I learned about '@', I
would always use substr() to remove the beginning part of the string
that I wanted to ignore.

   But that brings me to another question, one that concerns the usage
of the '/' construct.  I've used that construct before, but I could
never find an easy way to figure out my offset into the string after
I've used it.

   Let me clarify with an example.  Say I have the following piece of
code:

      my $string = "\x00\x01\x03\x00\x01\xff\x01\x0f";
      # or I could say:  my $sring = v0.1.3.0.1.255.1.15;
      my @x = unpack '@2 c/C', $string;

That would make @x have three elements:  0, 1, and 255.

   Now let's say that, after examining the contents of @x, I decide to
read in data for @y, starting where @x left off:

      my @y = unpack '@6 c/C', $string;

That would make @y have only one element:  15.

   However, in order to know that the second unpack command must start
at offset 6, I would have to calculate how many elements are in @x,
multiply that number by the space each element in @x takes (that is,
took up in the packed string), and add it to 2 (the first unpack()
offset) and add 1 (for the 'c' construct).  (This may not be too
complicated to do now, but it would be much more difficult to do with
a more complex unpack string, like "w/(c4 i L Z20)".)

   Is there a way for an unpack string to return the offset so that a
second unpack string can use it with the '@' construct?  This would
make dealing with variable-length extractions (for example, with 'w/'
and 'Z*') much easier.  I have read the "perldoc -f pack" and "perldoc
perlpacktut" pages but couldn't find anything about it (but maybe I
missed something).

   Thanks in advance for any help.

   -- Jean-Luc


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

Date: Fri, 13 Aug 2004 17:10:23 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Good way to un-chomp an array
Message-Id: <slrnchqf2f.cii.tadmc@magna.augustmail.com>

Scott W Gifford <gifford@umich.edu> wrote:
> "Suresh Govindachar" <initiallast-name@yahoo.xyz> writes:


>> What is a good way (with respect to speed)
>> to un-chomp an array?
> 
> This was the fastest way I could come up with:
> 
>   $_ .= "\n"
>     foreach @lines;


If we want unchomp(), then we'd better:

   $_ .= $/ foreach @lines;

so it will work even when the input record separator is not the default.


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


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

Date: 13 Aug 2004 22:47:16 GMT
From: Douglas Hunter <dug@plusthree.com>
Subject: Re: Good way to un-chomp an array
Message-Id: <slrnchqgvp.6lo.dug@plusthree.com>

On 2004-08-13, Tad McClellan <tadmc@augustmail.com> wrote:
>
> If we want unchomp(), then we'd better:
>
>    $_ .= $/ foreach @lines;
>
> so it will work even when the input record separator is not the default.
>

On my perl (5.8.3) this solution works when $/ is undef, but appends 
reference address when $/ is in fixed-length record mode.

ref $/ eq 'SCALAR' and undef $/;
$_ .= $/ foreach @lines;

seems to handle both situations.

-- Douglas Hunter



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

Date: 14 Aug 2004 00:01:45 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Good way to un-chomp an array
Message-Id: <Xns9544C182A4745castleamber@130.133.1.4>

"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in
news:y8aTc.32778$Mq1.1886754@news20.bellglobal.com: 

> 
> "Suresh Govindachar" <initiallast-name@yahoo.xyz> wrote in message
> news:mf9Tc.7355$54.112144@typhoon.sonic.net...
>> Hello,
>>
>> What is a good way (with respect to speed)
>> to un-chomp an array?
>>
>>       for(my $i=0; $i<scalar @lines; $i++)
> 
> So many ugly C-style for loops lately:
> 
> for my $i (0..$#lines)

Still ugly :-(

-- 
John                    Small Perl scripts:http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: 13 Aug 2004 18:49:28 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Good way to un-chomp an array
Message-Id: <86ekma32vr.fsf@blue.stonehenge.com>

*** post for FREE via your newsreader at post.newsfeed.com ***

>>>>> "Suresh" == Suresh Govindachar <initiallast-name@yahoo.xyz> writes:

Suresh> Hello,
Suresh> What is a good way (with respect to speed)
Suresh> to un-chomp an array?

Suresh>       for(my $i=0; $i<scalar @lines; $i++)
Suresh>       {
Suresh>           $lines[$i] .= "\n";
Suresh>       }

Ugh!  Subscripts!  Ugh!

  $_ .= "\n" for @lines;

print "Just another Perl hacker,"; # the original

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


 -----= Posted via Newsfeed.Com, Uncensored Usenet News =-----
http://www.newsfeed.com - The #1 Newsgroup Service in the World!
-----== 100,000 Groups! - 19 Servers! - Unlimited Download! =-----
                  


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

Date: Fri, 13 Aug 2004 22:10:14 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Good way to un-chomp an array
Message-Id: <slrnchr0km.k8n.tadmc@magna.augustmail.com>

John Bokma <postmaster@castleamber.com> wrote:
> "Matt Garrish" <matthew.garrish@sympatico.ca> wrote in
> news:y8aTc.32778$Mq1.1886754@news20.bellglobal.com: 
>> "Suresh Govindachar" <initiallast-name@yahoo.xyz> wrote in message
>> news:mf9Tc.7355$54.112144@typhoon.sonic.net...

>>> What is a good way (with respect to speed)
>>> to un-chomp an array?
>>>
>>>       for(my $i=0; $i<scalar @lines; $i++)
>> 
>> So many ugly C-style for loops lately:
>> 
>> for my $i (0..$#lines)
> 
> Still ugly :-(


But it has a great personality!


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


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

Date: Sat, 14 Aug 2004 10:30:14 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Good way to un-chomp an array
Message-Id: <UlpTc.36351$Mq1.2117164@news20.bellglobal.com>


"John Bokma" <postmaster@castleamber.com> wrote in message
news:Xns9544C182A4745castleamber@130.133.1.4...
> "Matt Garrish" <matthew.garrish@sympatico.ca> wrote in
> news:y8aTc.32778$Mq1.1886754@news20.bellglobal.com:
>
> >
> > "Suresh Govindachar" <initiallast-name@yahoo.xyz> wrote in message
> > news:mf9Tc.7355$54.112144@typhoon.sonic.net...
> >> Hello,
> >>
> >> What is a good way (with respect to speed)
> >> to un-chomp an array?
> >>
> >>       for(my $i=0; $i<scalar @lines; $i++)
> >
> > So many ugly C-style for loops lately:
> >
> > for my $i (0..$#lines)
>
> Still ugly :-(
>

Everyone else's baby is always uglier... : )

Granted there are other ways that don't require the array index, but it was
only meant as a drop-in replacement for the original.

Matt




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

Date: Sat, 14 Aug 2004 15:51:07 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Good way to un-chomp an array
Message-Id: <LxqTc.5362$SC1.3131@nwrddc03.gnilink.net>

Matt Garrish wrote:
> "John Bokma" <postmaster@castleamber.com> wrote in message
>> "Matt Garrish" <matthew.garrish@sympatico.ca> wrote in
>>> "Suresh Govindachar" <initiallast-name@yahoo.xyz> wrote in message
>>>>       for(my $i=0; $i<scalar @lines; $i++)
>>>
>>> for my $i (0..$#lines)
>
> Everyone else's baby is always uglier... : )
>
> Granted there are other ways that don't require the array index, but
> it was only meant as a drop-in replacement for the original.

You almost never need the array index in Perl. I would guess over 98% of all
array processing is done one element at a time and for that the canonical
form is

    for (@array) {
        process_element;
    }

The only exception (i.e. the only case where you need an array index) is if
in order to process a given element you need dynamic access to other array
element, e.g. in bubble sort to compare the element with its neighbor. But
in real life those case are surprisingly rare.

jue




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

Date: 14 Aug 2004 10:01:01 +0200
From: 510046470588-0001@t-online.de
Subject: Re: Good way to un-chomp an array
Message-Id: <87r7qab136.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me>

Scott W Gifford <gifford@umich.edu> writes:

> "Suresh Govindachar" <initiallast-name@yahoo.xyz> writes:
> 
> > Hello,
> > 
> > What is a good way (with respect to speed)
> > to un-chomp an array?
> 
> This was the fastest way I could come up with:
> 
>   $_ .= "\n"
>     foreach @lines;
> 
> I benchmarked it, your original, and a map-based solution, and found
> it was about 30% faster than your original, and about twice as fast as
> map:

it may make a difference whether 
the original array of strings is still needed or not.
(that's not clear from the context)
destructive operations are usually more efficient, 
but if the original needs to be preserved,
it requires deep copying first, 
which also should enter the benchmark.

Klaus Schilling


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

Date: Sat, 14 Aug 2004 00:44:12 +0100
From: "Paul Marquess" <Paul.Marquess@btinternet.com>
Subject: Re: howto convert a *nix DB_File to windows?
Message-Id: <2o522eF73ul0U1@uni-berlin.de>


"dan baker" <botfood@yahoo.com> wrote in message
news:13685ef8.0408131155.703f83b3@posting.google.com...
> I have a little application that saves data into a tied hash on a *nix
> webserver. I would like to be able to pull a copy local to my PC
> running windows 98 for testing and backup with as little pain as
> possible.
>
> So far the only way I've been able to do this is write export-import
> utilities to dump the DB to a text file and reload it at the other
> end. Gets to be a pain to maintain if fields change, etc. Is there a
> way to more directly convert the binary hash file that gets created to
> avoid this manual export-import conversion?
>
> ...I use a lot of the defaults for tie() when writing to the hash
> like:
>
> use DB_File;
> tie %tempHash , 'DB_File' , "${cfgRelPath_cgi2DB}/${dbfile}" ;
>         ... blah, blah, blah
>

If DB_File has been built with the same version of Berkeley DB on your Unix
box and your Windows box, the data files can be read on either.

Run this on your Unix box to find out what version of Berkeley DB the
DB_File module was built with:


       perl -e 'use DB_File; print qq{Berkeley DB ver $DB_File::db_ver\n}'

and this on the Windows box

       perl -e "use DB_File; print qq{Berkeley DB ver $DB_File::db_ver\n}"


Paul




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

Date: 14 Aug 2004 09:15:12 -0700
From: botfood@yahoo.com (dan baker)
Subject: Re: howto convert a *nix DB_File to windows?
Message-Id: <13685ef8.0408140815.5ee2743f@posting.google.com>

"Paul Marquess" <Paul.Marquess@btinternet.com> wrote in message 
> If DB_File has been built with the same version of Berkeley DB on your Unix
> box and your Windows box, the data files can be read on either.
> ---------------

Its a different version. I use the pre-compiled stuff from activestate
on windows, and the remote webserver has a little bit newer libs
installed. I move the files in binary mode, but they dont seem to be
compatible.

d


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

Date: Sat, 14 Aug 2004 18:22:04 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: howto convert a *nix DB_File to windows?
Message-Id: <2o6spoF7gnc6U1@uni-berlin.de>

dan baker wrote:
> Paul Marquess wrote:
>> If DB_File has been built with the same version of Berkeley DB on
>> your Unix box and your Windows box, the data files can be read on
>> either.
> 
> Its a different version. I use the pre-compiled stuff from
> activestate on windows, and the remote webserver has a little bit
> newer libs installed. I move the files in binary mode, but they
> dont seem to be compatible.

In your original post you were talking about a "little application".
If the hash is small as well, why not switch from DB_File to the
simple but compatible SDBM_File?

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


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

Date: 14 Aug 2004 09:46:24 +0200
From: 580046470588-0001@t-online.de
Subject: Re: howto convert a *nix DB_File to windows?
Message-Id: <87wu02b1rj.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me>

"Paul Marquess" <Paul.Marquess@btinternet.com> writes:

> "dan baker" <botfood@yahoo.com> wrote in message
> news:13685ef8.0408131155.703f83b3@posting.google.com...
> > I have a little application that saves data into a tied hash on a *nix
> > webserver. I would like to be able to pull a copy local to my PC
> > running windows 98 for testing and backup with as little pain as
> > possible.
> >
> > So far the only way I've been able to do this is write export-import
> > utilities to dump the DB to a text file and reload it at the other
> > end. Gets to be a pain to maintain if fields change, etc. Is there a
> > way to more directly convert the binary hash file that gets created to
> > avoid this manual export-import conversion?
> >
> > ...I use a lot of the defaults for tie() when writing to the hash
> > like:
> >
> > use DB_File;
> > tie %tempHash , 'DB_File' , "${cfgRelPath_cgi2DB}/${dbfile}" ;
> >         ... blah, blah, blah
> >
> 
> If DB_File has been built with the same version of Berkeley DB on your Unix
> box and your Windows box, the data files can be read on either.
> 
how about the BerkeleyDB module instead of DB_File? 
the later sleepycat versions provide much more functionality, 
like support for multi-writers/transactions/journaling

Klaus Schilling


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

Date: Fri, 13 Aug 2004 18:07:28 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: My own handy Pocket Reference notes (please share your own also)
Message-Id: <g39vu1-dm4.ln1@mauzo.dyndns.org>


Quoth Glenn Jackman <xx087@freenet.carleton.ca>:
> At 2004-08-11 08:52PM, David Filmer <IneverReadAnythingSentToMe@hotmail.com> wrote:
> >  To pass a only single hash to a subroutine (without using references):
> >     &MySubroutine(%foo);   #call the sub and pass it a hash directly
> >     sub MySubroutine () { my %bar = @_; }
> 
> You don't want the "()" prototype and the &, unless you have read
> perlsub thoroughly:
> 
>     MySubroutine(%foo);
>     sub MySubroutine { my %bar = @_; }

 ...however, you will then need to predeclare the sub with 'use subs'.

use subs qw/MySubroutine/;

 ...

MySubroutine %foo; # no need for parens, either

 ...

sub MySubroutine { ... }

Also, it is worth noting that is is more usual in Perl circles to use
names_like_this than NamesLikeThis orLikeThis.

Ben

-- 
I've seen things you people wouldn't believe: attack ships on fire off
the shoulder of Orion; I watched C-beams glitter in the dark near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die.                                                   ben@morrow.me.uk


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

Date: Sat, 14 Aug 2004 17:55:10 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: My own handy Pocket Reference notes (please share your own also)
Message-Id: <cflg5e$ic4$1@slavica.ukpost.com>

Ben Morrow wrote:

> Quoth Glenn Jackman <xx087@freenet.carleton.ca>:
> 
>>At 2004-08-11 08:52PM, David Filmer <IneverReadAnythingSentToMe@hotmail.com> wrote:
>>
>>> To pass a only single hash to a subroutine (without using references):
>>>    &MySubroutine(%foo);   #call the sub and pass it a hash directly
>>>    sub MySubroutine () { my %bar = @_; }
>>
>>You don't want the "()" prototype and the &, unless you have read
>>perlsub thoroughly:
>>
>>    MySubroutine(%foo);
>>    sub MySubroutine { my %bar = @_; }
> 
> 
> ...however, you will then need to predeclare the sub with 'use subs'.

Wrong on two counts.

You only need to predeclare subroutines that are calee without () or 
which have prototypes.

You can preclare with just

     sub MySubroutine;

there is no need for the subs pragma.



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

Date: Sat, 14 Aug 2004 16:03:08 GMT
From: Jeff Thies <jeff@spamalanadingong.com>
Subject: Re: noob question: use File::Copy;     
Message-Id: <0JqTc.18996$nx2.11702@newsread2.news.atl.earthlink.net>

<snip>

>    foreach ( glob '*.dat' ) {
>       copy( $_, 'temp-dir' ) or die...
>    }
> 
> 

I didn't know that copy could write to a directory. I thought that the 
file "temp-dir"  would simply contain the last read file of extension .dat.

Perldoc mentions nothing about directories.

Perldoc is a bit confusing at times, so I'm assuming that you are correct.

   Jeff


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

Date: Sat, 14 Aug 2004 12:28:37 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: noob question: use File::Copy;     
Message-Id: <slrnchsiu5.lke.tadmc@magna.augustmail.com>

Jeff Thies <jeff@spamalanadingong.com> wrote:
><snip>
> 
>>    foreach ( glob '*.dat' ) {
>>       copy( $_, 'temp-dir' ) or die...
>>    }
>> 
>> 
> 
> I didn't know that copy could write to a directory. 


You can't.


> Perldoc is a bit confusing at times, so I'm assuming that you are correct.


Perldoc  1,  Tad  0

( See? The docs are better than "some guy" on Usenet. If you can find
  an answer in the docs, that would be better than posting.
)


I guess I didn't see that the 2nd arg was meant to be a directory.

So I was not correct above, only below.  :-)


   copy( $_, "temp-dir/$_" ) or die...


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


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

Date: Sat, 14 Aug 2004 18:01:53 GMT
From: Jeff Thies <jeff@spamalanadingong.com>
Subject: Re: noob question: use File::Copy; 
Message-Id: <lssTc.25186$Jp6.14735@newsread3.news.atl.earthlink.net>

<snip>

> Perldoc  1,  Tad  0
> 
> ( See? The docs are better than "some guy" on Usenet. If you can find
>   an answer in the docs, that would be better than posting.
> )

Well at least you know I was paying attention!

I've just been reading -f utime

Which doesn't give you any indication of what either the first or second 
arg are! I like perldoc but it can leave you grasping for what others 
may assume is obvious.

   Jeff


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

Date: Fri, 13 Aug 2004 18:19:16 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: testing without shell access
Message-Id: <kp9vu1-dm4.ln1@mauzo.dyndns.org>


Quoth Joe Smith <Joe.Smith@inwap.com>:
> Tad McClellan wrote:
> 
> > You should always, yes *always*, check the return value from open():
> >    open (STDERR, '>scriptErr.txt') or die "could not open 'scriptErr.txt' $!";
> 
> open(STDERR,'>','scriptErr.txt') or die "Since STDERR is not open, you will 
> never see this message when die() is invoked, so you might as well give up."

 ...except that Perl keeps STDERR open to its old place if the open
fails.  AFAICT this only applies to the STD filehandles.

Ben

-- 
"If a book is worth reading when you are six,                * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis


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

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


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