[23766] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5970 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 22 21:05:46 2003

Date: Mon, 22 Dec 2003 18: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           Mon, 22 Dec 2003     Volume: 10 Number: 5970

Today's topics:
    Re: Add Files to Zip File <mikeflan@earthlink.net>
    Re: Best way to send contents of file as body of mail m <nospam@bigpond.com>
    Re: Escape $ in replace pattern: How to replace pattern <gnari@simnet.is>
    Re: Escape $ in replace pattern: How to replace pattern (Tad McClellan)
    Re: fork()/exec() in perl (Tad McClellan)
    Re: function-based hash lookup ? <usenet@morrow.me.uk>
    Re: function-based hash lookup ? (Jay Tilton)
    Re: help with file test <srsriram@sriram.com>
    Re: help with file test <gnari@simnet.is>
    Re: help with file test <noreply@gunnar.cc>
    Re: help with file test <matthew.garrish@sympatico.ca>
    Re: help with file test <matthew.garrish@sympatico.ca>
    Re: help with file test <gnari@simnet.is>
    Re: help with file test <gnari@simnet.is>
    Re: How to apend 1 file to another? (Sara)
    Re: invoking C-shell command through Perl script (Sara)
    Re: invoking C-shell command through Perl script (Tad McClellan)
    Re: ODBC: Is there something called text/csv database? <jgibson@mail.arc.nasa.gov>
    Re: Parsing File <jwillmore@remove.adelphia.net>
    Re: Parsing File <jwillmore@remove.adelphia.net>
    Re: Parsing File (Tad McClellan)
    Re: Parsing File (BrokenSaint)
        Perl DB question (Sara)
    Re: Planning for maintenance ctcgag@hotmail.com
    Re: replacing two EOL chars by one (Sara)
    Re: Return all points with x km of y ctcgag@hotmail.com
    Re: Starting Perl Script at Bootup <andy@petdance.com>
    Re: Starting Perl Script at Bootup <andy@petdance.com>
    Re: sum of numbers (Sara)
    Re: SWIG  sample compile problem <peter@nospam.calweb.com>
    Re: Tie::DBI problem -> new record is created instead o (Sara)
    Re: Win32: Output to console <jwillmore@remove.adelphia.net>
    Re: Win32: Output to console <usenet@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 23 Dec 2003 00:30:49 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Add Files to Zip File
Message-Id: <3FE78D83.80A14475@earthlink.net>


Anno Siegel wrote:

> There is no need for that.  Archive::Zip has methods to create
> an archive from a disk file, add members, and write the updated
> archive to a new file.  I'd recommend that.  If everything has
> worked out (see below), you can rename() the new file to the old
> name, completing the update.
>
> Note that the numeric file names you are using for member names are
> created by the news server.  They are only unique at one time in a
> single news group.  Once an article expires, the server is free to
> re-use the number.  If the server is allowed to update groups between
> runs, sooner or later you are going to write a member to an archive
> that already has that member.  I don't know how Archive::Zip handles
> that, but it's something to think of.
>
> [code snipped]
>
> Anno

Thanks for all your help.

I tried the code below right out of the example, but it
gives the error:
Can't locate object method "overwrite" via package "Archive::Zip::Archive"
 . . .
at line 47.

I guess I have a version problem here.  But I think I also
can't get my head around the terminology.  When
you say "create an archive from a disk file", you are
basically saying create a working copy of the zip file
that already contains zipped files.  At least that is
my understanding.

Keep in mind that I am on Win2000.  I'm probably a
month or more from getting my Linux machine set up.



Mike



#use strict;
#use warnings;

# Shows how to update a Zip in place using a temp file.
# $Revision: 1.1 $
#
use Archive::Zip qw(:ERROR_CODES);
use File::Copy();

my $zipName = 'file.zip';
my @fileNames = 'file12.doc', 'file13.doc', 'file15.doc', 'file16.doc';
die 'must provide file names' unless scalar(@fileNames);

chdir 'C:/copy2';

# Read the zip
my $zip = Archive::Zip->new();
die "can't read $zipName\n" unless $zip->read($zipName) == AZ_OK;

# Update the zip
foreach my $file (@fileNames)
{
 $zip->removeMember($file);
 if ( -r $file )
 {
  if ( -f $file )
  {
   $zip->addFile($file) or die "Can't add $file to zip!\n";
  }
  elsif ( -d $file )
  {
   $zip->addDirectory($file) or die "Can't add $file to zip!\n";
  }
  else
  {
   warn "Don't know how to add $file\n";
  }
 }
 else
 {
  warn "Can't read $file\n";
 }
}

# Now the zip is updated. Write it back via a temp file.

exit( $zip->overwrite() ); # THIS IS LINE 47-----------


__END__


__________________________________________________________


Well now I have it.  I replaced line 47 with
exit( $zip->writeToFileNamed("file2.zip") );
and it works.

Now I need to write the whole script and replace the
non-Perl method I've already placed into production.


Thanks again,


Mike




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

Date: Tue, 23 Dec 2003 08:43:55 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Best way to send contents of file as body of mail message with Mail::Mailer?
Message-Id: <2697353.7J17Zeefna@gregs-web-hosting-and-pickle-farming>

It was a dark and stormy night, and James Willmore managed to scribble:

> On 22 Dec 2003 08:40:10 -0800
> lsrtech@optonline.net (lsrtech) wrote:
> 
 ...
> Just a suggestion - you could look over the MIME::Lite module.  That
> may fit the bill better.  It allows you to attach files to an email
> and set the MIME type of the attachment.  This may be more what you're
> looking for - I think :-)
> 
> HTH


Mime::Lite is the way to go - simple & lots of good examples in the documentation.

gtoomey


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

Date: Mon, 22 Dec 2003 22:01:11 -0000
From: "Ragnar Hafstaš" <gnari@simnet.is>
Subject: Re: Escape $ in replace pattern: How to replace pattern "a*c" by exact string "p$1q"
Message-Id: <bs7pju$ufp$1@news.simnet.is>

"him1508" <himanshu.deshpande@contractor.thomson.com> wrote in message
news:dd6b6779.0312220823.586304fb@posting.google.com...
> Hi,
>
> I'm a novice to perl. For search and replace of strings, I'm using the
> jakarta ORO Regex package which uses Perl5 internally. I need to build
> a perl pattern for the search string and replace string. It is working
> fine for all cases except this:
>
> search pattern : a*c
> replace string  (not pattern, exact string): pqr$1xyz
>
> Search in : jkhjha8ctwe
> Expected result: jkhjhpqr$1xyztwe
>
you may be aware that this is not a pure perl s/// substitution,
so unless someone here is familiar with the package, your info is not enough
for us to help you with.
in particular, it might be enlightening to see example of cases that 'work
fine'
and how they differ from the ones that do not.
also, you give us the expected result but not the actual result.

(I am assuming here that another similar substitution did actually
work in the manner you described. if on the other hand real perl
substitutions
are supposed to work, you could try the pattern a(.*)c

gnari






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

Date: Mon, 22 Dec 2003 14:27:59 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Escape $ in replace pattern: How to replace pattern "a*c" by exact string "p$1q"
Message-Id: <slrnbuekuf.4lj.tadmc@magna.augustmail.com>

him1508 <himanshu.deshpande@contractor.thomson.com> wrote:

> search pattern : a*c
> replace string  (not pattern, exact string): pqr$1xyz
>  
> Search in : jkhjha8ctwe
> Expected result: jkhjhpqr$1xyztwe


No, the expected result is:  jkhjha8pqr$1xyztwe

Did you mean to use a.*c for the pattern instead?


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


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

Date: Mon, 22 Dec 2003 17:05:45 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: fork()/exec() in perl
Message-Id: <slrnbueu69.4lj.tadmc@magna.augustmail.com>

Huey <huey_jiang@yahoo.com> wrote:

> I need my perl script to call C program:


   perldoc -f system

   perldoc -q external


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


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

Date: Mon, 22 Dec 2003 22:23:41 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: function-based hash lookup ?
Message-Id: <bs7qtd$gkv$1@wisteria.csv.warwick.ac.uk>


krichine@juno.com (Kirill Richine) wrote:
> Is it possible to modify the behavior of hash key lookup?

perldoc perltie

Ben

-- 
And if you wanna make sense / Whatcha looking at me for?          (Fiona Apple)
                            * ben@morrow.me.uk *


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

Date: Tue, 23 Dec 2003 00:06:16 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: function-based hash lookup ?
Message-Id: <3fe786d9.251709738@news.erols.com>

krichine@juno.com (Kirill Richine) wrote:

: For example, if I have a hash containing strings that I want to detect
: in a file:
: 
: %h = ('string1' => 1, 'string2' => 2, ...);
: 
: I currently have to do manual search:
: 
: while (<>) {
:   foreach $e (keys %h) {
:     print "$_" if ($_ =~ $e);
            ^  ^
            ^  ^
See perlfaq4, " What's wrong with always quoting "$vars"? "

:   }
: }
: 
: Is it possible to avoid the manual looping through keys but instead
: use something like:
: 
: sub key_match {
:   $a =~ $b;
: }
: 
: while (<>) {
:   print "$_" if $h{&key_match $_};
                     ^
                     ^
It doesn't have anything to do with the solution described below, but
the "foo()" form of subroutine call is preferred over the "&foo" form.  

: }

: In other words, by default $h{$b} will find value only if $b equals
: exactly an existing key in %h.
: Is there a way to modify the "equals exactly" behavior of hash lookup?

Yes.  The hash can be tied to a class that uses pattern matching to find a
value.  The Tie::RegexpHash module on CPAN provides that capability.

    use Tie::RegexpHash;
    tie my %h, 'Tie::RegexpHash';
    %h = ('string1' => 1, 'string2' => 2 );
    while(<DATA>) {
        chomp;
        print "$_ => $h{$_}\n" if $h{$_};
    }
    __DATA__
    This line contains string1.
    This line contains nothing important.
    This line contains string2.



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

Date: Mon, 22 Dec 2003 17:28:49 -0600
From: "S.R.Sriram" <srsriram@sriram.com>
Subject: Re: help with file test
Message-Id: <3FE77E31.8EE2B18E@sriram.com>

James Willmore wrote:
> 
> Where  is $BASEDIR being defined in the Perl script?  Or, are you
> making the assumption that Perl will import $BASEDIR from your
> environment?
> 
> To import $BASEDIR (if, in fact, that's what you're doing), you need
> to do something like ....
> (untested)
> 
> my $basedir  = 'put some default directory here';
> $basedir = $ENV{BASEDIR} if defined $ENV{BASEDIR};
> 
> This should import the environment variable BASEDIR if BASEDIR is
> defined in the shell.  However, if it isn't defined, we already set a
> default directory to use (just in case and to avoid getting a warning
> about an undefined variable).
> 
> HTH
> 
> --
> Jim

$BASEDIR is the name of the directory. 
mkdir $BASEDIR

It is not a variable to be imported.

For the directory i gave in my example:

/var/newbinary/$BASEDIR/bin/foo

when i have to cd into this directory, i need to escape the "$".

cd /var/newbinary/\$BASEDIR/bin/

My issue is that in my above code snippet, when i 

if (-e /var/newbinary/\$BASEDIR/bin/foo) {
	&doSomething;
} else {
	&doSomethingDifferent;
}

always invokes the "else" leg even though the file "foo" exists.

Thanks,
Sriram


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

Date: Mon, 22 Dec 2003 23:49:37 -0000
From: "Ragnar Hafstaš" <gnari@simnet.is>
Subject: Re: help with file test
Message-Id: <bs7vv3$upp$1@news.simnet.is>

"S.R.Sriram" <srsriram@sriram.com> wrote in message
news:3FE77E31.8EE2B18E@sriram.com...
> $BASEDIR is the name of the directory.
> mkdir $BASEDIR
>
> It is not a variable to be imported.
>
> For the directory i gave in my example:
>
> /var/newbinary/$BASEDIR/bin/foo
>
> when i have to cd into this directory, i need to escape the "$".
>
> cd /var/newbinary/\$BASEDIR/bin/
>
> My issue is that in my above code snippet, when i
>
> if (-e /var/newbinary/\$BASEDIR/bin/foo) {
> &doSomething;
> } else {
> &doSomethingDifferent;
> }
>
> always invokes the "else" leg even though the file "foo" exists.

why dont you post actual code instead of something you have not really
tested.
I will have to guess that you are having quote problems
try one of
   if (-e "/var/newbinary/\$BASEDIR/bin/foo") {
or
   if (-e '/var/newbinary/$BASEDIR/bin/foo') {

do they work? if not post a snippet that will actually compile, ok?

gnari





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

Date: Tue, 23 Dec 2003 01:26:23 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: help with file test
Message-Id: <bs822g$9vdim$1@ID-184292.news.uni-berlin.de>

S.R.Sriram wrote:
> $BASEDIR is the name of the directory.

Okay. Odd, but possible.

> For the directory i gave in my example:
> 
> /var/newbinary/$BASEDIR/bin/foo
> 
> when i have to cd into this directory, i need to escape the "$".
> 
> cd /var/newbinary/\$BASEDIR/bin/

To my knowledge, cd is not a Perl command. Are referring to a shell
command from the command prompt?? You should not assume that you can
make any conclusions out from that as regards the need to escape
things in Perl.

> My issue is that in my above code snippet, when i
> 
> if (-e /var/newbinary/\$BASEDIR/bin/foo) {

Do you always write strings in Perl code without quotes? Suppose not.
Please show us what you actually wrote, or else it's hard to help you.

Btw, have you studied the posting guidelines for this group?
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

In your previous message you said that you did:

     $fileName =~ s/\$/\\\$/g;

         if (-e $fileName) {

etc., but if $fileName had been assigned the string
'/var/newbinary/$BASEDIR/bin/foo', you should _not_ add that
backslash.

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



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

Date: Mon, 22 Dec 2003 19:38:31 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: help with file test
Message-Id: <98MFb.4677$d%1.1045837@news20.bellglobal.com>


"S.R.Sriram" <srsriram@sriram.com> wrote in message
news:3FE7184A.CFAED73E@sriram.com...
> Hi,
>
> In the following code, the file test operator ( -e $fileName) works for
some
> cases only.
>
> ###########code snippet#######
> :
> :
> ($fileType,$fileName,$fileSize,$fileSum) = (split('
',$pkgMapLine))[0,1,2,3];
>
> if ($fileType eq "f") {
>
> $fileName =~ s/\$/\\\$/g;
>

Why are you escaping the dollar sign? Instead of trying to verify:

$fileName = /var/newbinary/$BASEDIR/bin/foo

you're now testing:

$fileName = /var/newbinary/\$BASEDIR/bin/foo

Perl does not interpolate variables when you use the file test operators, so
there's no need to be escaping any characters.

Matt




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

Date: Mon, 22 Dec 2003 19:57:18 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: help with file test
Message-Id: <JpMFb.4704$d%1.1052150@news20.bellglobal.com>


"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:98MFb.4677$d%1.1045837@news20.bellglobal.com...
>
> Perl does not interpolate variables when you use the file test operators,
so
> there's no need to be escaping any characters.
>

A regrettable sentence on rereading. What I was trying to say is that if you
use a variable for your pathname, interpolation will not occur on the value
within the variable. So if your variable has a $ in it, it will be treated
as a plain old dollar sign.

Matt




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

Date: Tue, 23 Dec 2003 01:05:07 -0000
From: "Ragnar Hafstaš" <gnari@simnet.is>
Subject: Re: help with file test
Message-Id: <bs84cl$v40$1@news.simnet.is>

"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:98MFb.4677$d%1.1045837@news20.bellglobal.com...
>
> "S.R.Sriram" <srsriram@sriram.com> wrote in message
> news:3FE7184A.CFAED73E@sriram.com...
> >
> Perl does not interpolate variables when you use the file test operators,
so
> there's no need to be escaping any characters.

can you explain what you mean by that. surely when executing:
      $x="foo";
      print "$x is a file\n" if -f $x;
the $x is iterpolated

and to test a file literally called $x, you need to do:
      print "\$x is a file\n" if -f '$x';

so what are you refering to in the sentence quoted above?

gnari





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

Date: Tue, 23 Dec 2003 01:22:42 -0000
From: "Ragnar Hafstaš" <gnari@simnet.is>
Subject: Re: help with file test
Message-Id: <bs85dl$v4g$1@news.simnet.is>

"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:JpMFb.4704$d%1.1052150@news20.bellglobal.com...
>
> "Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
> news:98MFb.4677$d%1.1045837@news20.bellglobal.com...
> >
> > Perl does not interpolate variables when you use the file test
operators,
> so
> > there's no need to be escaping any characters.
> >
>
> A regrettable sentence on rereading. What I was trying to say is that if
you
> use a variable for your pathname, interpolation will not occur on the
value
> within the variable. So if your variable has a $ in it, it will be treated
> as a plain old dollar sign.

ok. then feel free to ignore my previous followup.

gnari




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

Date: 22 Dec 2003 13:29:26 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: How to apend 1 file to another?
Message-Id: <776e0325.0312221329.7ad878ee@posting.google.com>

Uri Guttman <uri@stemsystems.com> wrote in message news:<x78yl9ahiq.fsf@mail.sysarch.com>...
> >>>>> "PI" == Public Interest <test@test.com> writes:
>  
>   > is there a way to apend it without read it first? such as cat a.txt b.txt >
>   > b.txt
> 
> don't top post. read the group guidelines (posted regularly)
> 
> what do you think cat is doing there, twiddling its thumbs? it is
> reading the file. and that shell example has a classic bug in it.
> 
> and even if you fixed the bug, it reads the second file which is not
> needed.
> 
> file systems don't usually provide ways of moving data without reading
> them. so how would you do it without reading the file?
> 
> and you asked for a perl solution and i gave you one. what more do you want?
> 
> uri

Uri you're not very Jolly for Christmastime :~ 

Just kidding have a nice holiday!!

G


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

Date: 22 Dec 2003 13:06:56 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: invoking C-shell command through Perl script
Message-Id: <776e0325.0312221306.6d27dc57@posting.google.com>

micha.ofir@zoran.com (Micha Ophir) wrote in message news:<cec9398b.0312220740.26bd2796@posting.google.com>...
> Hi,
> 
> I was looking for an answer in several places incloding the FAQ in
> perl.com .
> 
> I invoked C-shel through perl like this :
> `ls *.v`;
> or like this :
> system ("ls *.v");
> 
> Here are the questions :
> 1. How can I cause the C-Shell / perl to output the standart output 
>    to the screen. ( usually I don't see it ).
> 2. How can I set environment variables in C-Shell through the perl.
>    When I set the variables in the perl code, and then invoke the C-shell 
>    command the variables are not set.
>    Example :
> $ENV{PATH_TO_FILE} = "all_you_need_is_love";  ## set the variable 
> `echo $PATH_TO_FILE` ;  ## doesn't know the variable
> 
> Thanks in advance.
> 
> Ophir Micha

its not a particularly good idea to turn control over to OS commands
for a number of reasons, portability being one good one. Error control
being another.

I'd advise you to look at opendir / readdir to accomplish what you're
trying to do. If you insist on using the OS command, perhaps you can
capture the result in a scalar and print it:

#!/usr/bin/perl -wd
 my $cat = `ls *`;
 print $cat;

As for ENV Vars- again portabiity might be a concern. Do you want the
var to persist after the script exits? If so, an OS command might be a
viable alternative. If you're trying to set the var to do some sort of
inter-process communication, you might consider portable alternatives.
Perl has a nice library of file sharing methods for locking, testing
status, changing permissions, etc on files. Store results in a file
and have the other script open and read it?

If you don't need it to persist, just add it to %ENV as you did:

    $ENV{MyFavoriteHobbit} = 'Bilbo';

realzing of course that the scope of this definition is only the scope
of %ENV, which of course cannot exist outside of the script itself
(wll unless you tie it, but even then it won't affect the ssytem ENV
VAR tables).


Happy Holidays,
G


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

Date: Mon, 22 Dec 2003 17:12:57 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: invoking C-shell command through Perl script
Message-Id: <slrnbueujp.4lj.tadmc@magna.augustmail.com>

Micha Ophir <micha.ofir@zoran.com> wrote:

> I invoked C-shel through perl like this :
> `ls *.v`;
> or like this :
> system ("ls *.v");


Neither of those invoke the csh.

Both of those invoke /bin/sh.


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


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

Date: Mon, 22 Dec 2003 11:07:29 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: ODBC: Is there something called text/csv database?
Message-Id: <221220031107292038%jgibson@mail.arc.nasa.gov>

In article
<i9PEb.494877$0v4.21605097@bgtnsc04-news.ops.worldnet.att.net>, Social
Liberal-Fiscal Conservative <test@test.com> wrote:

> How to check what module I have installed? I did perldoc dbi, but nothing
> found.
> 
> 

Case may be significant for module names, although it is not in my
version (5.8.2). Try "perldoc DBI". If you get nothing, chances are you
don't have it installed.

Your second question is an FAQ. Try "perldoc -q modules".


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

Date: Mon, 22 Dec 2003 20:38:04 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Parsing File
Message-Id: <20031222153804.64e8de33.jwillmore@remove.adelphia.net>

On Mon, 22 Dec 2003 18:11:52 +0000 (UTC)
"John J. Trammell" <trammell+usenet@hypersloth.invalid> wrote:
> On Mon, 22 Dec 2003 17:50:43 GMT, James Willmore
> <jwillmore@remove.adelphia.net> wrote:
> > On 22 Dec 2003 07:37:19 -0800
> > genericax@hotmail.com (Sara) wrote:
> >> tartemp@epix.net (BrokenSaint) wrote in message
> >> news:<24813030.0312201921.3708d8f0@posting.google.com>...
> > 
> >>   die "duuuh gee Tenessee it wont even open!\n" 
> >>    unless open F, 'myBigoleFile.dat';
> > 
> > You *really* mean 
> > my $filename = '/path/name_of_file';
> > open F, "$filename" or die "Can't open $filename: $!\n";
>           ^         ^
> > right?
> 
> Useless use of quotes; I've always liked:
>   open(F,$filename) or die "Can't open '$filename': $!";
> but TMTOWDTI!

True - very true. TMTOWTDT. ;-)

> 
> [snip]
> 
> > And why 'unless'?  Please, explain *why* you check 'open' in such
> > a way.  It's more efficent to try and open the file first, *then*
> > die if you can't. 
> 
> **boggle**
> HIBT?
> 

?? Huh ??  That's one I haven't seen.  HIBT?  Please clarify.

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
"I know not with what weapons World War III will be fought, but
World War IV will be fought with sticks and stones."   -- Albert
Einstein 


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

Date: Mon, 22 Dec 2003 20:44:32 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Parsing File
Message-Id: <20031222154432.0352f6a3.jwillmore@remove.adelphia.net>

On Mon, 22 Dec 2003 20:38:04 GMT
James Willmore <jwillmore@remove.adelphia.net> wrote:

> True - very true. TMTOWTDT. ;-)

TMTOWTDI - IFU (I Fouled Up) :-)

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Going to church does not make a person religious, nor does going 
to school make a person educated, any more than going to a garage
makes a person a car. 


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

Date: Mon, 22 Dec 2003 14:30:30 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Parsing File
Message-Id: <slrnbuel36.4lj.tadmc@magna.augustmail.com>

James Willmore <jwillmore@remove.adelphia.net> wrote:

> You *really* mean 
> 
> my $filename = '/path/name_of_file';
> open F, "$filename" or die "Can't open $filename: $!\n";
          ^         ^
          ^         ^
> right?


Not right, because it has a useless use of double quotes.

:-)


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


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

Date: 22 Dec 2003 16:07:08 -0800
From: tartemp@epix.net (BrokenSaint)
Subject: Re: Parsing File
Message-Id: <24813030.0312221607.5085f8e1@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<bs7cph$e3r$1@mamenchi.zrz.TU-Berlin.DE>...
> Sara <genericax@hotmail.com> wrote in comp.lang.perl.misc:
> > tartemp@epix.net (BrokenSaint) wrote in message
> > news:<24813030.0312201921.3708d8f0@posting.google.com>...
> > > i have a file with the following data:
> > > ...
> > > Record created on 24-Jun-2003.
> > > Database last updated on 27-Nov-2003 17:14:03 EST.
> > > 
> > > Domain servers in listed order:
> > > 
> > > ns00.nameserver.com 123.456.789.012
> > > ns00.nameserver.com 123.456.789.012
> > > =====================================================
> > > What i would like to do is parse thru the file and find and retain
> > > "NS99.WORLDNIC.COM" to a variable. The data i desire almost always is
> > > available after the words "Domain servers...:"
> > > =====================================================
> > > The following 2 formats are common:
> > > Domain servers in listed order:
> > > 
> > > ns00.nameserver.com 123.456.789.012
> > > ns00.nameserver.com 123.456.789.012
> > >                      OR
> > > Domain servers: ns00.nameserver.com
> > > ++++++++++++++++++++++++++++++++++++++++
> > > 
> > > If someone can help me with this, it would be appreciated
> > 
> > OK this code is untested (for example, I'm sure it wont work for all
> > types of domain names, and probably myriad other boundry conditions
> > which Anno will surely point out) ,
> 
> Oh no.  It's much more fun pointing out glitches the author *hasn't*
> anticipated...
> 
> >                                     and I'm not entirely sure of what
> > you're seeking in the file, but you might consider something like:
> > 
> >   die "duuuh gee Tenessee it wont even open!\n" 
> 
> ...like the missing "n" in "Tennessee".
> 
> Like you, I'm not sure what the OP is trying to extract from the file, so
> I can't be sure what you are trying to do in the code below.  I'll do
> my best to criticize it anyhow.
> 
> >    unless open F, 'myBigoleFile.dat';
> > 
> > # the \n? is there in case the last line has no EOL
> > # should work as long as the name is the first one on the line
> 
> The linefeed matters only because you have chosen to extract a pattern
> by first assigning the whole string and then changing the string to
> what was matched.  That is inefficient and cumbersome, as you have
> seen.  You have worried less about text that may precede the match,
> but it deserves similar consideration.
> 
> >  map s/(\w+\.\w+\.\w+/).+\n?/$1/, (my @data) = grep
>                        ^
> You don't want that backslash, it's a syntax error.  It's annoying little
> slips like that what makes us prefer when people test their code.
> 
> > /\w+\.\w+\.\w+/,<F>;
> > 
> >   close F;
> 
> I don't doubt it does what it's intended to do, but yours is a rather
> peculiar construction.  The map() should really be a "for" here (you're
> not interested in the list of 1s map returns), and the assignment in the
> middle of a statement isn't particularly readable either.  As mentioned,
> pattern extraction by pattern substitution is in general not recommended.
> 
> I don't mind peculiar constructions if they serve a purpose, but this
> is a standard situation:  Watch lines passing by and extract matches
> to a particular pattern.  The standard solution is
> 
>     my @data;
>     while ( <F> ) {
>         push @data, $1 if /(\w+\.\w+\.\w+)/;
>     }
> 
> ... or, if you prefer a one-liner involving map()
> 
>     my @data = map /(\w+\.\w+\.\w+)/, <DATA>;
> 
> Anno

I appologize for my ignorance on how the post groups work. First time
posting to a site, will be more diligent in posting my code for review
going forward, but thnx anyways


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

Date: 22 Dec 2003 13:20:39 -0800
From: genericax@hotmail.com (Sara)
Subject: Perl DB question
Message-Id: <776e0325.0312221320.a44b659@posting.google.com>

I often want to break on the first line of a block, such as


21  while ($itsANiceDay)
22    {print "lets play outdoors\n";
23     $itsANiceDay = getWeatherReport();
24    }


I can set a breakpoint on like 21 or 23, but why not 22? It looks like
a legitimate place to break?

G


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

Date: 22 Dec 2003 22:08:58 GMT
From: ctcgag@hotmail.com
Subject: Re: Planning for maintenance
Message-Id: <20031222170858.637$gS@newsreader.com>

"Derek.Moody" <derek.moody@clara.net> wrote:
>
> Opinions solicited:
> If you were hired to maintain my legacy (say 50 scripts, 8 modules) which
> form would you prefer?
> As you may guess I favour the second version - am I overlooking any
> potential pitfalls?

I think it would depend on how many times per script these things are
used, and how intensive is the maintenance they are likely to need.  The
fewer and less, the more I'd favor fully resolved names.


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: 22 Dec 2003 13:17:24 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: replacing two EOL chars by one
Message-Id: <776e0325.0312221317.6f7378f5@posting.google.com>

tiltonj@erols.com (Jay Tilton) wrote in message news:<3fe4bd0e.68951468@news.erols.com>...
> xah@xahlee.org (Xah Lee) wrote:
> 
> : i have a bunch of java files that has spaced-out formatting that i
> : want to get rid of. I want to replace two end of line characters by
> : one end of line characters. The files in question is unix, and i'm
> : also working under unix, so i did:
> : 
> :  perl -pi'*~' -e "s@\n\n@\n@g" *.java
> : 
> : but this to no avail.
> 
> Of course it's not.
> 
> Perl's -p switch processes one line at a time.  A line cannot have more
> than one newline character.
> 
> Perl's "paragraph" reading might be useful to you, where any number of
> consecutive newline characters mark the end of a record.  See "$/" in
> perlvar for details.
> 
>     perl -i'*~' -lpe "BEGIN{$/=''}" *.java
> 
> : after many minutes of checking and rechecking and lots of trial and
> : error with frustration, i realized that the fucking perl to my
> : expectations again cannot do this simple fucking thing.
> 
> Complete nonsense.  Don't blame your own incompetence on Perl.
> 
> : Fucking stupid perl
> : documentation and Larry Wall moron who is i believe incapable of
> : writing clearly and logically in English masquerading as humor.
> 
> If you feel you can explaint it more clearly, quit bellyaching about it and
> submit a documentation patch.
> 
> Preferrably one that is less petulant and profane than your article.
> Frustration is no excuse for incivility.

is incivility a word? Curious. Anyhow, if I understand this you want
to replace two \n's with one? How about this (untested) code:

  die "Perl is ever so much smarter than Java\n" unless open F,
'myfile';
  my @f = <FILE>
  close F;

  $f = join '',@f;
  $f =~ s/(\n)\n/$1/gs;

 die "Hmm this file cant be opened for writing\n" unless open F,
'>myfile';
  print F $f;
  close F;

  print "Perl does it again!\n\n";


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

Date: 23 Dec 2003 00:19:45 GMT
From: ctcgag@hotmail.com
Subject: Re: Return all points with x km of y
Message-Id: <20031222191945.701$Qg@newsreader.com>

"Ian Pattison" <ianp@pop3.myrealbox.com> wrote:
>
> Thanks for all of your assistance on this one. Both for the programming
> ideas as well as the geography/math lessons.
>
> My final result: I found a module on CPAN that would do all the
> calculations I needed. (Geo-Distance-0.05) and from there it was simple.
>
> In response to Bob's question... I'm using Win32:ODBC to pull data from
> an access database. Currently there are about 30 tables, each with around
> 32,000 rows but in essence I'm using it as a flat file. I'm still working
> exactly how to get the nearest, say, 500 to a given point but finding all
> the ones with X km is done.

I'd start by doing something like:

my @data;
while (my($key,$dist)=next_point()) {
   push @data, [$key,$dist];
};
@data = (sort {$a->[1]<=>$b->[1]})[0..$x-1];

And if that took too much memory I'd do:

my @data;
while (my($key,$dist)=next_point()) {
   push @data, [$key,$dist];
   @data = (sort {$a->[1]<=>$b->[1]} @data)[0..$x-1] if @data>$x*8;
};
@data = (sort {$a->[1]<=>$b->[1]} @data)[0..$x-1];


And if that didn't cut I'd seriously look into getting a real
GIS before I'd spend more time on rolling my own.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: Mon, 22 Dec 2003 14:39:39 -0600
From: Andy Lester <andy@petdance.com>
Subject: Re: Starting Perl Script at Bootup
Message-Id: <3FE7568B.1030009@petdance.com>

>>To get a useful answer, even if it's not the right place to do it.
>>Far better than a malicious lie.

> You may want to take your sarcasm/irony detector to the shop for a
> readjustment.

It's not mine I'm concerned about.  It's the person who originally 
posted the question.

I'd like to think that the person who happens to post in an incorrect 
newsgroup doesn't deserve an incorrect answer.

We were all rookies at one point.

xoa



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

Date: Mon, 22 Dec 2003 14:48:05 -0600
From: Andy Lester <andy@petdance.com>
Subject: Re: Starting Perl Script at Bootup
Message-Id: <3FE75885.1070400@petdance.com>

>>To get a useful answer, even if it's not the right place to do it.
>>Far better than a malicious lie.

> You may want to take your sarcasm/irony detector to the shop for a
> readjustment.

It's not mine I'm concerned about.  It's the person who originally
posted the question, who has no way of knowing that Abigail's answer is 
wrong.

I'd like to think that the person who happens to post in an incorrect
newsgroup doesn't deserve an incorrect answer.

We were all rookies at one point.

xoa




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

Date: 22 Dec 2003 13:26:00 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: sum of numbers
Message-Id: <776e0325.0312221326.7ac7e109@posting.google.com>

Tassos <chatasos@yahoo.com> wrote in message news:<1071828484.212677@athnrd02.forthnet.gr>...
> Is there a way to find the sum of the following numbers (stored in a file) using a single 
> line (perl -pe) command?
> 
> 
> 254257
> 52658768
> 19320
> 135
> 5070180
> 14392
> 7113
> 24415
> 34983006
> 7329
> 50584
> 24481
> 91
> 8339
> 14407

Carsten Aulbert <carsten@welcomes-you.com> wrote in message news:<bruj5h$7mdei$1@ID-213226.news.uni-berlin.de>...
> Tassos wrote:
> > Is there a way to find the sum of the following numbers (stored in a 
> > file) using a single line (perl -pe) command?
> 
> Yes ;-)
> 
> Simply write a small script and put all commands on a single line.
> 
> CA

well said CA I like that!

Tassos, there are myraid ways to do this. One nice trick is to "join"
the numbers with "+", then eval the string. Can get ugly if you have
non-numbers in the mix however, but then I'm sure you know how to
error-check your file.

G


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

Date: Mon, 22 Dec 2003 13:25:36 -0800
From: Penguinista <peter@nospam.calweb.com>
Subject: Re: SWIG  sample compile problem
Message-Id: <3fe76039$0$7490$d368eab@news.calweb.com>

Alex wrote:
> This just introduced a lot of new errors..
> I couldn't comment out the sys/types include because it's in one of the
> files that I shouldn't have to be editing. I don't think that's the problem,
> something else is causing it.
> I did add direct.h to the path. It comes up with a lot more errors now, but
> it also seems to still have trouble finding the file:
> In file included from /cygdrive/c/perl/lib/core/sys/socket.h:20,
>                  from /cygdrive/c/perl/lib/core/perl.h:709,
>                  from hello_wrap.c:291:
> /cygdrive/c/perl/lib/core/win32.h:75:20: direct.h: No such file or directory
> If I'm in bash or just cmd.exe and I type direct.h it will find the file and
> try to open it. Why is this still broken then?
> 
> Alex
> 
> 
grep direct.h /cygdrive/c/perl/lib/core/win32.h
to see how direct.h is referenced.  the search path may need adjustment.

gcc -c hello.c hello_wrap.c -I/cygdrive/c/perl/lib/core -I/path/to/direct

(remembering again why I dislike M$ as a software developement environment.)



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

Date: 22 Dec 2003 13:12:21 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: Tie::DBI problem -> new record is created instead of updating existing one
Message-Id: <776e0325.0312221312.17974cfc@posting.google.com>

"Zoltan Kandi" <notpublic@restricted.com> wrote in message news:<BIDFb.379$wS4.8912@news.uswest.net>...
> Hi group,
> 
> This was posted a week ago on c.l.p.modules. Since I did not get any
> answers, decided to post here as well. Apologies in advance for the ugly
> cross-posting.
> 
> Example taken with modiications from
> http://search.cpan.org/~lds/Tie-DBI-0.93/lib/Tie/DBI.pm
> 
> I'm running Windows XP, MySQL server 3.23.49, ActiveState Perl 631 and the
> following relevant modules:
> 
> DBD-mysql          [2.1026 ] A MySQL driver for the Perl5 Database Interface
> (DBI)
> DBI                      [1.37   ] Database independent interface for Perl
> Tie-DBI                [0.93   ]
> 
> I created a MySQL test database as follows:
> 
> create table test (testid integer not null,testdata char(100) not null)
> insert into test values(1,"EFGHHHHHHHHHHHHHHHHHHHHHHHH")
> 
> and ran the following test script:
> 
> use strict;
> use warnings;
> use DBI();
> 
> my (%h,@keys,$key,$value);
> 

   .
   .
   .

> Any clues/hints will be appreciated.
> 
> Thanks in advance,
> 
> Zoltan

Dear Mr Zoltan:

Hey loved you in that Tom Hanks movie.

I don't understand why yuo're putting yourself through all of this
with the ties. Those are OK for DBM or GDBM, but for a real database
like mysql why not just use the usual mysel DBD driver, and fetch the
rows you need? If this database gets sizable (which in my experience
they ALL pretty much do eventually), tie-ing will be an unmanageable
way to deal with it anyhow.


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

Date: Mon, 22 Dec 2003 20:41:57 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Win32: Output to console
Message-Id: <20031222154157.415b73d6.jwillmore@remove.adelphia.net>

On 22 Dec 2003 10:42:54 -0800
google@psyonix.com (Dave...) wrote:
<sniped for brevity>
> Is there a way to output in real time the way it works on the
> commandline or could someone explain to me why it cannot be done?

Look over the IPC::Open2 and IPC::Open3 modules (standard with Perl). 
They *may* give you what you want.

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Green light in a.m. for new projects.  Red light in P.M. for
traffic tickets. 


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

Date: Mon, 22 Dec 2003 22:39:02 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Win32: Output to console
Message-Id: <bs7rq6$hkc$1@wisteria.csv.warwick.ac.uk>


google@psyonix.com (Dave...) wrote:
> I'm using Perl on a windows machine to automate Visual Studio .NET C++
> builds each day. The command I run is the VS commandline program
> devenv.exe which outputs log and error information to the console if
> run directly on the commandline. For some reason I am unable to
> capture or redirect this output to the console when I run the command
> from Perl until the entire build is complete. Using system() I get no
> ouput at all

Have you closed/reopened STD{IN,OUT,ERR}? All my experience on Win32
suggests that commands run with system() from a perl process running
in a console window inherit thir STD handles from the parent, and will
output to the console if that's where they still point.

You could try system "devenv ... >CON: <CON: 2>CON:", or you could try
reopening STD{IN,OUT,ERR} to "CON:" before calling system(). You could
try uning Win32::Process instead.

If you want to capture the output rather than simply have it go to the
console, I think you're out of luck. Command-line programs test
whether their input is a console; if it is, they empty their output
buffer every line, if it isn't, they buffer in huge chunks for
efficiency. Under unix you'd use a special type of file called a
'pty', which is basically a two-way pipe that pretends to be a
console. I don't think there is any equivalent on win32.

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.  

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


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