Re: What is a "case shell"?

2001-04-24 Thread Paul Johnson

On Tue, Apr 24, 2001 at 06:37:34PM -0500, Dennis Fox wrote:
> Here is a line from a job description that has me baffled: "·Perl
> scripting (must know how to Perl well enough to script inside a case
> shell)"
> 
> Leaving aside the use of "Perl" as a verb for another discusssion, is
> this just a typo (common in job advertisements), or is there a "case
> shell" that I have not heard of yet? The company with this ad uses
> Solaris (does not say which version).

I suspect they are talking about a CASE tool of some description.
Computer Aided Software Engineering aka Big Brother :-)

I've no idea how this can possibly require a specific set of Perl
skills unless it is learning some proprietry library about which they
are silent.

Type CASE tool into Google or look up the FAQ for comp.software-eng to
find out more.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net



RE: Looking for perl specifications on the net

2001-04-24 Thread Peter Scott

At 10:06 AM 4/24/2001 +1000, King, Jason wrote:

>Roiy Zysman writes ..
>
> > Hi guys and girls , does any one have a web link to perl specifications,
> > (For example, are the specifications for a variable name) ??
>
>while others have pointed you to perlstyle - to me your question reads more
>that you're after the technical specifications of what can and can't be
>included in Perl

Actually, no formal specification of Perl exists.  Whether one should is an 
issue that comes up occasionally and there are vocal proponents of both 
positions.  I would like to see one one day.

You can find most of what you need to in the documentation.  But a formal 
specification, like the ANSI C standard, doesn't exist.




How to read OutLook E-Mails?

2001-04-24 Thread Helio S. Junior

Hello,


I have a WebPage here in our intranet and i would like
to know if it's possible to look for specific Outlook
e-mails when the user 'refreshes' the Page.

When one user clicks on the Refresh Button, i have to
read e-mails from a specific folder in OutLook 2000
and
update a Table inside my page.

Is it possible to do it with Perl?

Any sample code?

Thanks in Advance,


H3li0


__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Fw: installing Term::ReadKey module on Windows

2001-04-24 Thread James A Culp III

*Apologies for the duplicate Janet, I forgot to CC: the list*

ActiveState has a package TermReadKey, this is the ActiveState *read
'windows'* version of Term::ReadKey.

To access the ActiveState packages you should have ActiveState Perl
installed on your windows machine.  At the DOS prompt:
C:\> ppm

then at the PPM prompt

PPM> install TermReadKey

The package should be downloaded and installed with no hitches.  If this
isn't the module you are referring too please correct me.

James

> - Original Message -
> From: "Lee, Janet" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, April 24, 2001 11:06 PM
> Subject: installing Term::ReadKey module on Windows
>
>
> > Hi all.
> >
> > I'm having difficulty installing the Term::ReadKey module which was
> > suggested to me. From what I can tell, I need to compile
> it--unfortunately,
> > I've never compiled any C programs on my Windows machine before, so I
> don't
> > have gcc installed. I have three questions:
> > 1) Am I right that I need gcc to install this module?
> > 2) Is there a pre-compiled version of this module available? I didn't
find
> > one on CPAN, but perhaps someone has one...? I'm working on a WinME
> machine,
> > but I would be happy to try anything compiled on Win95 or up.
> > 3) Assuming that the answers to the previous two questions are yes and
no
> > respectively, what's the best place to get a copy of gcc? A link would
be
> > suffcient.
> >
> > TIA
> > janet
>





Re: failure notice

2001-04-24 Thread Holmes F. Boroughf


Within the headers of messages sent out by this mailing list are the
following lines:

Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm
List-Post: 
List-Help: 
List-Unsubscribe: 
List-Subscribe: 
Delivered-To: mailing list [EMAIL PROTECTED]
To: Perl <[EMAIL PROTECTED]>

Your email program may have hidden the List lines for you and will
only show them to you if you turn on some obscure option. This
information is most helpful and is worth a kudo to the list manager
who provides it.

There is also a Digest version of this mailing list that consolidates
the list traffic into fewer (larger) emails and is a little easier to
follow. Information lines from the headers of the digest list are:
List-Post: 
List-Help: 
List-Unsubscribe: 
List-Subscribe: 
Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm

The quality and quantity of good information provided by the PERL
Beginners mailing list make the digest version well worth
investigating.

Sincerely

>How do I remove this mailing list from my account? This e-mail account can't
>receive the massive amounts of mail which this list generates.
>
>Thanks,
>Eric



installing Term::ReadKey module on Windows

2001-04-24 Thread Lee, Janet

Hi all.

I'm having difficulty installing the Term::ReadKey module which was
suggested to me. From what I can tell, I need to compile it--unfortunately,
I've never compiled any C programs on my Windows machine before, so I don't
have gcc installed. I have three questions:
1) Am I right that I need gcc to install this module?
2) Is there a pre-compiled version of this module available? I didn't find
one on CPAN, but perhaps someone has one...? I'm working on a WinME machine,
but I would be happy to try anything compiled on Win95 or up.
3) Assuming that the answers to the previous two questions are yes and no
respectively, what's the best place to get a copy of gcc? A link would be
suffcient. 

TIA
janet



Re: How do I nest quote characters in a print command?

2001-04-24 Thread Paul


--- Eric Hanigan <[EMAIL PROTECTED]> wrote:
> Hello,
> Real greenhorn here. I'm modifying a discussion board script which
> writes to an html file. I'm trying to insert the following into the
> file: 
> 
> So, I put this in the script:
> print "   \n";
> 
> I'm getting syntax errors. I'm pretty sure it's from the quote
> character before the word titlepic (that's what I think the error log
> on the server is telling me). That quote is closing off an argument,
> right?

I'd say so. =o)
 
> How do I nest the quoted material within the other quotes? I've tried
> qq and \Q amongst other things, but I don't know what I'm doing.

LOTS of options. =o)

First, the internal quotes are probably not really necessary, if you're
willing no be out of true on your HTML specs.

 print "   \n";

Not a good habit, but it'd likely work.
Better, switch quotes:

 print "   \n";

Sometimes that's not going to do, such as when you have to print an
HREF with a javascript mouseOver, so you can use qq:

 print qq{\n};

(And yes, you can even embed that newline.)

Or my personal favorite, the "here-document". This is a
little-documented Perl feature that has saved me a lot of trouble.

print<
END

You can even do assignments to variables with this, which works great
for javascript you need to write to several consecutive pages, for
example when you use code to write hard pages to disk:

my $js=<<'END'; # and comments here are ok, too!

 write whole javascript functions here, with embedded nested quotes and
whatever else. Because I quoted 'END' in the =<<'END' above, everything
is kept exactly as in single-ticks. This text runs until it finds END
on a line by itself, though leading whitespace causes confusion. 

END

Hopefully that's more than you need without getting you confused. Play
with it some. It'll work.

Drop me another note if it doesn't!

Paul

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



[OT]Re: What is a "case shell"?

2001-04-24 Thread Paul


--- Greg Meckes <[EMAIL PROTECTED]> wrote:
> I'm sure it's ksh (k shell - Unix). The person placing the ad
> probably dictated to the person who
> actually put the ad in and misunderstood.

Not that they could actually say "Korn shell".
lol

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



inserting text into file

2001-04-24 Thread Morgan Seppy

I've inserted text into a file before, but I can't seem to figure this one
out.  I'm trying to create a guestbook / message list.  I'm taking
information from a form and trying to insert it at a certain spot in a
file, namely, the top of the list.  My form works fine and I have no trouble
getting the information into the file, but it keeps appending to the end of
the file.

These are the first few lines in guestbook.html:








    list of entries in table form 



Perl program snippet:

open( GBOOK, "+<../htdocs/guestbook.html" ) or die( "Couldn't open GBOOK:
$!\n" );

# Find top of list and insert entry
while(  )
{
   if( /^$/ )
   {
   print GBOOK "found TOP\n";
   ... #  add  new entry
   }
}

close( GBOOK ) or die( "Couldn't close GBOOK: $!\n" );


Originally, I had the first line of the while() as
next unless  /^$/ ;
but that didn't work either, so since then it has been kludged into the
above version.

My confusion is apparent in these questions:
1.  Why doesn't my regex work?
2.  Why does the entry get added at the end of the file if the regex
failed?

Thanks for any help you can provide,

Morgan
[EMAIL PROTECTED]




Re: sysread and buffering

2001-04-24 Thread sfink

Paul wrote:
> 
> Another possible solution is to use Brian Ingerson's Inline.pm and code
> the reads &c. with C's lower level IO. I think a C getc() would do
> it
> 
> But be warned that, while it's actually quite friendly, a raw beginner
> might have some trouble with the Inline stuff, especially if they don't
> know C. I'd say look, maybe try, and decide based on your own
> confidence.

sysread() correctly bypasses all the buffering that it can. getc()
straight from C will be no better (it calls the same read() that
sysread() does.) The buffering is happening in the tty layer, which is
not making any data available until a return key is pressed. You'll need
something like Term::ReadKey. Do

perldoc perlfaq8

to see a complete description of this.



How do I nest quote characters in a print command?

2001-04-24 Thread Eric Hanigan

Hello,
Real greenhorn here. I'm modifying a discussion board script which writes 
to an html file. I'm trying to insert the following into the file:



So, I put this in the script:

print "   \n";

I'm getting syntax errors. I'm pretty sure it's from the quote character 
before the word titlepic (that's what I think the error log on the server 
is telling me). That quote is closing off an argument, right?

How do I nest the quoted material within the other quotes? I've tried qq 
and \Q amongst other things, but I don't know what I'm doing.

Thanks for any tips,

Eric




RE: sysread and buffering

2001-04-24 Thread Lee, Janet

In case inquiring minds would like to know...

Actually, the reason why I am trying to do this in PERL in the first place
is because I couldn't figure out how to do it in C++ on a UNIX machine
(getchar is not supposed to buffer, but it does in some cases). I thought I
would try it in PERL on UNIX and/or Windows to see if there was a
difference. But portability is a plus. So I'm off to try to load a couple of
PERL modules (turns out I need Time:HiRes also) and see if I can get this
working. But the C/UNIX related hints are useful to read also. Thanks to
all.

Janet

PS Someone here at work solved the C/UNIX problem for me too, it had to do
with concatanation...



Re: Complex Regex.

2001-04-24 Thread David H. Adler

On Tue, Apr 24, 2001 at 01:38:45PM -0400, Timothy Kimball wrote:
> 
> I've only been on the list a couple of days, and I've already seen a
> couple of questions about regexes matching numbers.

...and I don't remember anyone mentioning Damian Conway's mind-boggling
Regexp::Common module:

   By default, this module exports a single hash ("%RE") that stores
   or generates commonly needed regular expressions (see the section
   on "List of available patterns").

Which might simplify this greatly for numbers of any complexity.

dha
-- 
David H. Adler - <[EMAIL PROTECTED]> - http://www.panix.com/~dha/
All right!  So I'm the daughter of poison gas!
- Sybil Crane, The Big Bus



Re: What is a "case shell"?

2001-04-24 Thread Greg Meckes

I'm sure it's ksh (k shell - Unix). The person placing the ad probably dictated to the 
person who
actually put the ad in and misunderstood.


-g


__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



RE: What is a "case shell"?

2001-04-24 Thread blowther

Might be a phonetic thing... perhaps they are referring to the ksh (K
Shell)?

-Original Message-
From: Dennis Fox [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 24, 2001 5:38 PM
To: [EMAIL PROTECTED]
Subject: What is a "case shell"?


Here is a line from a job description that has me baffled: "·Perl
scripting (must know how to Perl well enough to script inside a case
shell)"

Leaving aside the use of "Perl" as a verb for another discusssion, is
this just a typo (common in job advertisements), or is there a "case
shell" that I have not heard of yet? The company with this ad uses
Solaris (does not say which version).

If it is just about using "case" in a shell script, I already know how
to do that.

Thanks for any light y'all can shed.

-- 
-
Dennis "Bass Dude" Fox  | [EMAIL PROTECTED]  OR 
[EMAIL PROTECTED]
Bureaucracy is the art of making the possible impossible
-Javier Pascual Salcedo
-



What is a "case shell"?

2001-04-24 Thread Dennis Fox

Here is a line from a job description that has me baffled: "·Perl
scripting (must know how to Perl well enough to script inside a case
shell)"

Leaving aside the use of "Perl" as a verb for another discusssion, is
this just a typo (common in job advertisements), or is there a "case
shell" that I have not heard of yet? The company with this ad uses
Solaris (does not say which version).

If it is just about using "case" in a shell script, I already know how
to do that.

Thanks for any light y'all can shed.

-- 
-
Dennis "Bass Dude" Fox  | [EMAIL PROTECTED]  OR 
[EMAIL PROTECTED]
Bureaucracy is the art of making the possible impossible
-Javier Pascual Salcedo
-



RE: Help on lib/modules Please!!

2001-04-24 Thread Arante, Susan

That solves the problem.  You're wonderful!!

Thanks to everyone for all the help and ideas!!!

/susan

-Original Message-
From: Sean O'Leary [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 24, 2001 2:58 PM
To: [EMAIL PROTECTED]
Subject: Re: Help on lib/modules Please!!


At 05:08 PM 4/24/2001, you wrote:
>I had a pm that used to be working and is called using "use ABC::Test;".  I
>deleted (for some stupid reasons) the perl directory and didn't realize I
>also deleted the ABC subdirectory below site\lib.  I took another copy from
>another machine and placed it back under site\lib but now I'm getting this
>error message when I try to do "use ABC::Test;" - on Perl 5.  Any ideas?
>
>Can't locate loadable object for module ABC::Test in @INC (@INC contains:
>c:/perl/lib c:/perl/site/lib .) at - line 1

There's more to this module than just Perl code.  You need to look in 
/perl/site/lib/auto, and look for ABC/test there.  Copy all that stuff to 
the same path on the other machine, and you should be good to go.

Perl is in this case looking for an external .dll that implements some 
functionality of ABC::Test, and if it can't load that .dll at compile time, 
it won't have the code to run at runtime, so it prudently dumps you 
out.  That 'loadable object' part tells you it's looking for something 
compiled, not plain Perl.  The auto directory described above is where all 
this kind of compiled code is stored so that DynaLoader or something can 
find it when it needs it.  (XS gurus - It is DynaLoader that loads these 
libs, right?)

Check out perlmod, perlmodlib, and perlmodinstall for the gory 
details.   You may also need to drop in on perlxstut, and perlxs for all 
the info.  That's where things get really gory.  Oops... no that would be 
perlguts.  : )  And you might need to read that too.

Oh, just FYI, when Perl needs to call into an external library, .dll or .so 
or whatever you system calls them, it's done through a mechanism called XS, 
for eXternal Subroutines, or sometimes XSUBs.  These XSUBs are kinda hairy 
to write, unless you are a relatively accomplished C programmer, and have a 
good knowledge of how Perl internally handles data structures and 
operations.  If you saw Paul's post mentioning Inline.pm, it's job is to 
make it much simpler to write XSUBs.

And after what I said to Paul, I feel like a total tool mentioning both 
Inline and XS in the same post on a "beginners" mailing list.  Somebody 
rein me in!  : )

Thank you for your time,

Sean.



Re: pulling out part of a /path/to/a/file

2001-04-24 Thread Sandor W. Sklar

Thanks to everyone who answered; Casey's suggestion is the easist for 
me to 'grok', and so that is what I'm going with.

This list is a great thing!

Thanks, all ...

-s-

At 12:04 PM -0400 4/24/01, Casey West wrote:
>On Tue, Apr 24, 2001 at 09:52:04AM -0700, Sandor W. Sklar wrote:
>: Hi, folks ...
>:
>: I'm generating a list of files (from a find subroutine) and putting
>: them in an array.  The list looks like ...
>:
>: /home4/dsadmin/7790/DocuShare/documents/b003/File-11523.1
>: /home4/dsadmin/7790/DocuShare/documents/b003/File-11587.1
>: /home4/dsadmin/7790/DocuShare/documents/b003/File-11651.1
>: /home4/dsadmin/7790/DocuShare/documents/b004/File-1156/html/main.htm
>: /home4/dsadmin/7790/DocuShare/documents/b004/File-1604/html/main.htm
>:
>: (... a small sample)
>:
>: and I'm trying to get just the "File-" part of each line; some
>: lines that I am matching against will have a trailing slash, with
>: additional path info that I'm not interested in; other lines will
>: have a period and a number following, which I am also not interested
>: in.
>:
>: Perhaps the File::Basename module would do what I want, but I can't
>: get my mind around its documentation.  I thought of using split on
>: each line (splitting on the "/", and then looking each element of the
>: array returned), but that seems, well, stupid.  I'm sure that there
>: is some really simple magic here; I just don't see it.  Can someone
>: enlighten me please?
>
>Well, if you're just interested in a fast, easy way of doing this,
>where you always know that there will be 'File-' and then some
>numbers, try:
>
>#!/usr/local/bin/perl -w
>use strict;
>$|++;
>
>while (  ) {
>   my( $part ) = /(File-\d+)/; # In list context ( forced by using
>   # parens with my() ), a match will
>   # return a list of matches.  In this
>   # case, one match.
>   print "I like this $part\n";
>}
>
>__END__
>/home4/dsadmin/7790/DocuShare/documents/b003/File-11523.1
>/home4/dsadmin/7790/DocuShare/documents/b003/File-11587.1
>/home4/dsadmin/7790/DocuShare/documents/b003/File-11651.1
>/home4/dsadmin/7790/DocuShare/documents/b004/File-1156/html/main.htm
>/home4/dsadmin/7790/DocuShare/documents/b004/File-1604/html/main.htm
>
>
>--
>Casey West

-- 
sandor w. sklar
unix systems administrator
stanford university itss-css



Re: Help on lib/modules Please!!

2001-04-24 Thread Michael Lamertz

Arante, Susan ([EMAIL PROTECTED]) wrote:
> 
> Can't locate loadable object for module ABC::Test in @INC (@INC contains:
> c:/perl/lib c:/perl/site/lib .) at - line 1

Dan's suggestion sounds good.  Look into a directory that describes your
machine type and processor below the site directory.  Perhaps there's
more of your 'ABC'-structure lying around, since that's where the
compiled C-libraries go.

E.g., I have on my machine two Apache-Trees:

/usr/lib/perl5/site_perl/5.6.0/Apache

that's the obvious one, and

/usr/lib/perl5/site_perl/5.6.0/i386-linux/Apache

here's the other part.

-- 
 If we fail, we will lose the war.

In most states the penalty for an adult who rapes a child is twenty
years plus -- UNLESS that adult happens to be related to the child, in
which case the maximum sentence is PROBATION. There is legislation now
pending in Congress to change all this. IF YOU CARE, ACT!
http://www.careact.org 

Michael Lamertz  | [EMAIL PROTECTED] / [EMAIL PROTECTED]
Nordstr. 49  | http://www.lamertz.net
50733 Cologne| Work: +49 221 3091-121
Germany  | Priv: +49 221 445420 / +49 171 6900 310



Re: @INC variable :please help

2001-04-24 Thread Michael Lamertz

Rajakumar Theja ([EMAIL PROTECTED]) wrote:
> Hi,
> 
> I'm new to perl, so please help.
> My installation of DBD::Oracle for Oracle 8.1.6
> failed.
> After reaching a dead end and not getting any help
> from 
> dbi-users, I decided to copy over a previous
> installation of the perl directory tree which
> includes DBI and DBD from another machine.

Whoa!  This is an absolute nono.  Depending on what other packages you
built, what compiler and local libraries you have, what Oracle Version
you have running, you can break all sorts of stuff.

I guess rebuilding a fresh perl is - with the help of the CPAN module
usually faster than figuring out library dependencies for hours.

*WARNING*  CPAN works best if you have a direct internet connection.  A
socks proxy will do too, but I have no idea how things are with a
http-proxy.


What was the problem with the DBD build?  As a hint, you need the Oracle
samples installed, since these provide the headers you need to compile
the DBD stuff.


Assuming you're on some Unix box, here are some general pointers of how
I would continue from here.  *THINK HARD BEFORE YOU TRY THIS*.

If you decide to reinstall, save the old tree in case something really
breaks.  Then take a deep look at the 'site-perl' directory tree inside
perl's lib directory, and write down the packages that have been
installed there.  As a rule of thumb, all directories inside your local
site-perl tree correspond to a package name.  Additionally, you have to
look into the directory that describes your machine type, e.g.
"i386-linux".  Things that lie there should also correspond to CPAN
packages.

Move the complete perl tree to the side, fetch the sources and do the
usual things to build perl - should be something like:

./Configure -Dprefix=/where/you/want/it -Dcc=your-compiler -des
make
make test
make install

then continue with

perldoc CPAN

then, after reading do 

perl -MCPAN -e shell

follow the setup procedure and start installing the packages you noted
earlier.

DBD::Oracle will most probably fail to install from out of the CPAN
module, so be prepared to build this by hand by typing 'look CPAN' in
the CPAN shell prompt.

Keep asking if you're stuck...

Mike

-- 
 If we fail, we will lose the war.

Michael Lamertz  | [EMAIL PROTECTED] / [EMAIL PROTECTED]
Nordstr. 49  | http://www.lamertz.net
50733 Cologne| Work: +49 221 3091-121
Germany  | Priv: +49 221 445420 / +49 171 6900 310



x

2001-04-24 Thread McKenney, Sue

unsubscribe




Re: are there any binaries for OS/2

2001-04-24 Thread Dan Brown

Please go to

http://www.perl.com/

There is a pulldown menu at the top right.  Make sure "binaries" is
selected.  Click the 'go' button to the right of this pulldown.  You'll
get a list of binary distributions (OS/2 is in the list).

Dan

Calin Popa wrote:
> 
> Hi, are there ani perl5 binaries for OS/2 Warp?
> 
> =
> Calin
> 
> __
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/



Re: Help on lib/modules Please!!

2001-04-24 Thread Sean O'Leary

At 05:08 PM 4/24/2001, you wrote:
>I had a pm that used to be working and is called using "use ABC::Test;".  I
>deleted (for some stupid reasons) the perl directory and didn't realize I
>also deleted the ABC subdirectory below site\lib.  I took another copy from
>another machine and placed it back under site\lib but now I'm getting this
>error message when I try to do "use ABC::Test;" - on Perl 5.  Any ideas?
>
>Can't locate loadable object for module ABC::Test in @INC (@INC contains:
>c:/perl/lib c:/perl/site/lib .) at - line 1

There's more to this module than just Perl code.  You need to look in 
/perl/site/lib/auto, and look for ABC/test there.  Copy all that stuff to 
the same path on the other machine, and you should be good to go.

Perl is in this case looking for an external .dll that implements some 
functionality of ABC::Test, and if it can't load that .dll at compile time, 
it won't have the code to run at runtime, so it prudently dumps you 
out.  That 'loadable object' part tells you it's looking for something 
compiled, not plain Perl.  The auto directory described above is where all 
this kind of compiled code is stored so that DynaLoader or something can 
find it when it needs it.  (XS gurus - It is DynaLoader that loads these 
libs, right?)

Check out perlmod, perlmodlib, and perlmodinstall for the gory 
details.   You may also need to drop in on perlxstut, and perlxs for all 
the info.  That's where things get really gory.  Oops... no that would be 
perlguts.  : )  And you might need to read that too.

Oh, just FYI, when Perl needs to call into an external library, .dll or .so 
or whatever you system calls them, it's done through a mechanism called XS, 
for eXternal Subroutines, or sometimes XSUBs.  These XSUBs are kinda hairy 
to write, unless you are a relatively accomplished C programmer, and have a 
good knowledge of how Perl internally handles data structures and 
operations.  If you saw Paul's post mentioning Inline.pm, it's job is to 
make it much simpler to write XSUBs.

And after what I said to Paul, I feel like a total tool mentioning both 
Inline and XS in the same post on a "beginners" mailing list.  Somebody 
rein me in!  : )

Thank you for your time,

Sean.




RE: Global symbol requires explicit pack name

2001-04-24 Thread blowther

I pretty printed for my own sanity:

use strict ;
my @vob_list = `cleartool lsvob | grep "*"`;
my $entry ;
foreach $entry (@vob_list) {
  chomp $entry;
  my @fields = split /\s+/, $entry;
  my $tag_list ;
  my $vbs_list ;
  @tag_list = @fields[1] ;
  @vbs_list = @fields[2] ;
  foreach my $lock (@tag_list) {
print "$lock \n" ;
foreach my $tardir (@vbs_list) {
  print "$tardir \n" ;
}
  }
}

You need to declare the variables referenced in the foreach statements.  I
put my in front of both.

The other two errors related to the lines:

  my $tag_list ;
  my $vbs_list ;
  @tag_list = @fields[1] ;
  @vbs_list = @fields[2] ;

This is a common mistake for new folks...  you're declaring two scalars, but
you're actually assigning into two different arrays.

In perl, $tag_list is a completely different variable than @tag_list.  One
is a scalar (single value) and the other is an array.  To access an item
within the array, you reference it in a scalar context:

$tag_list = $fields[1];

Hope this helps

Bruce W. Lowther
Micron Technology, Inc.
Boise, Idaho


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 24, 2001 3:41 PM
To: [EMAIL PROTECTED]
Subject: Global symbol requires explicit pack name




All,
 When I use strict function, I get an error in the following code.
#!/usr/local/bin/perl
use strict ;
my @vob_list = `cleartool lsvob | grep "*"`;
my $entry ;
foreach $entry (@vob_list) {
chomp $entry;
my @fields = split /\s+/, $entry;
my $tag_list ;
my $vbs_list ;
@tag_list = @fields[1] ;
@vbs_list = @fields[2] ;
foreach $lock (@tag_list) {
print "$lock \n" ;
foreach $tardir (@vbs_list) {
print "$tardir \n" ;
}
}
}

Global symbol "tag_list" requires explicit package name at ./back.pl line
10.
Global symbol "vbs_list" requires explicit package name at ./back.pl line
11.
Global symbol "lock" requires explicit package name at ./back.pl line 12.
Variable "@tag_list" is not imported at ./back.pl line 12.
Global symbol "tag_list" requires explicit package name at ./back.pl line
12.
Variable "$lock" is not imported at ./back.pl line 13.
Global symbol "lock" requires explicit package name at ./back.pl line 13.
Global symbol "tardir" requires explicit package name at ./back.pl line 14.
Variable "@vbs_list" is not imported at ./back.pl line 14.
Global symbol "vbs_list" requires explicit package name at ./back.pl line
14.
Variable "$tardir" is not imported at ./back.pl line 15.
Global symbol "tardir" requires explicit package name at ./back.pl line 15.
Execution of ./back.pl aborted due to compilation errors.

I get this error only when I use the strict function, so I figured that this
is
not an efficient code. Can somebody help me on this ?

Thx in advance
Kailash




Re: How to send attacments>

2001-04-24 Thread M.W. Koskamp


- Original Message - 
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, April 22, 2001 12:28 AM
Subject: How to send attacments>


How do i send an html file as an attachment using sendmail?
Thanks

Take a look at the MIME::Lite module...




Re: Global symbol requires explicit pack name

2001-04-24 Thread Andy Sharp

Hi,

The error message you're getting is one of the many changes to the
nature of perl under strict.  It usually means that the variable in
question needs to be either  explicitely named (via
$::Package::Variable) or lexically scoped (via my, our, or use vars).

you've made a couple errors here, which are only raised using strict.

> my $tag_list ;
> my $vbs_list ;
> @tag_list = @fields[1] ;
> @vbs_list = @fields[2] ;

Here, you've pre-declared a SCALAR variable $tag_list and two line later
you're using an ARRAY (list) variable to hold the results. 
Additionally, when you refer to @fields[1] you are probably trying to
refer to $fields[1]  (because when you refer to a slice of an array, you
need to in a scalar fashion.  (think - an array is two dimensional, but
the slice to which you refer is only one value)

so change that to my $tag_list = $fields[1];  you can declare with my at
the same time as assigning the initial value, in this case the second
slice of @fields.  (the first slice is $fields[0])

Next, in the line:
foreach $lock (@tag_list) {

It is not being declared or scoped, try:  
foreach my $lock (@tag_list) {

(there's a few more just like that that you need to change)

You'll need to scope each of your variables when running under strict,
which is a better programming habit, and one of the many reasons it's
reccommended to use strict.

Hope that helps,

--A


[EMAIL PROTECTED] wrote:
> 
> All,
>  When I use strict function, I get an error in the following code.
> #!/usr/local/bin/perl
> use strict ;
> my @vob_list = `cleartool lsvob | grep "*"`;
> my $entry ;
> foreach $entry (@vob_list) {
> chomp $entry;
> my @fields = split /\s+/, $entry;
> my $tag_list ;
> my $vbs_list ;
> @tag_list = @fields[1] ;
> @vbs_list = @fields[2] ;
> foreach $lock (@tag_list) {
> print "$lock \n" ;
> foreach $tardir (@vbs_list) {
> print "$tardir \n" ;
> }
> }
> }
> 
> Global symbol "tag_list" requires explicit package name at ./back.pl line 10.
> Global symbol "vbs_list" requires explicit package name at ./back.pl line 11.
> Global symbol "lock" requires explicit package name at ./back.pl line 12.
> Variable "@tag_list" is not imported at ./back.pl line 12.
> Global symbol "tag_list" requires explicit package name at ./back.pl line 12.
> Variable "$lock" is not imported at ./back.pl line 13.
> Global symbol "lock" requires explicit package name at ./back.pl line 13.
> Global symbol "tardir" requires explicit package name at ./back.pl line 14.
> Variable "@vbs_list" is not imported at ./back.pl line 14.
> Global symbol "vbs_list" requires explicit package name at ./back.pl line 14.
> Variable "$tardir" is not imported at ./back.pl line 15.
> Global symbol "tardir" requires explicit package name at ./back.pl line 15.
> Execution of ./back.pl aborted due to compilation errors.
> 
> I get this error only when I use the strict function, so I figured that this is
> not an efficient code. Can somebody help me on this ?
> 
> Thx in advance
> Kailash



How to send attacments>

2001-04-24 Thread a

How do i send an html file as an attachment using sendmail?
Thanks




Re: Help on lib/modules Please!!

2001-04-24 Thread Dan Brown

The error message you include points to some "loadable object" that Perl
is looking for.  Did Test.pm by chance reference a library?  Is that
library present somewhere in one of the directories included in @INC?

Perl can find Test.pm.  It cannot find something that Test.pm needs.  If
Perl cannot find a module you'd get an error like

Can't locate Test.pm in @INC (@INC contains: ...

Dan

"Arante, Susan" wrote:
> 
> I had a pm that used to be working and is called using "use ABC::Test;".  I
> deleted (for some stupid reasons) the perl directory and didn't realize I
> also deleted the ABC subdirectory below site\lib.  I took another copy from
> another machine and placed it back under site\lib but now I'm getting this
> error message when I try to do "use ABC::Test;" - on Perl 5.  Any ideas?
> 
> Can't locate loadable object for module ABC::Test in @INC (@INC contains:
> c:/perl/lib c:/perl/site/lib .) at - line 1



Re: Global symbol requires explicit pack name

2001-04-24 Thread Paul


--- [EMAIL PROTECTED] wrote:
> 
> 
> All,
>  When I use strict function, I get an error in the following
> code.
> #!/usr/local/bin/perl
> use strict ;
> my @vob_list = `cleartool lsvob | grep "*"`;
> my $entry ;
> foreach $entry (@vob_list) {
> chomp $entry;
> my @fields = split /\s+/, $entry;

Watch these.

> my $tag_list ;
> my $vbs_list ;
> @tag_list = @fields[1] ;
> @vbs_list = @fields[2] ;

See anything amiss?
You declared $tag_list, a scalar, but you're using @tag_list, and
array.
Since you never declared the array, it's looking for it as a global,
and there isn't one.


To fix
> foreach $lock (@tag_list) {

say:
 
 foreach my $lock (@tag_list) {

The same syntax works for the rest of these.

> print "$lock \n" ;
> foreach $tardir (@vbs_list) {
> print "$tardir \n" ;
> }
> }
> }
> 
> Global symbol "tag_list" requires explicit package name at ./back.pl
> line 10.
> Global symbol "vbs_list" requires explicit package name at ./back.pl
> line 11.
> Global symbol "lock" requires explicit package name at ./back.pl line
> 12.
> Variable "@tag_list" is not imported at ./back.pl line 12.
> Global symbol "tag_list" requires explicit package name at ./back.pl
> line 12.
> Variable "$lock" is not imported at ./back.pl line 13.
> Global symbol "lock" requires explicit package name at ./back.pl line
> 13.
> Global symbol "tardir" requires explicit package name at ./back.pl
> line 14.
> Variable "@vbs_list" is not imported at ./back.pl line 14.
> Global symbol "vbs_list" requires explicit package name at ./back.pl
> line 14.
> Variable "$tardir" is not imported at ./back.pl line 15.
> Global symbol "tardir" requires explicit package name at ./back.pl
> line 15.
> Execution of ./back.pl aborted due to compilation errors.
> 
> I get this error only when I use the strict function, so I figured
> that this is not an efficient code. Can somebody help me on this ?

It's just helping you get used to the way Perl works. =o)

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Re: [beginner] file parsing question

2001-04-24 Thread M.W. Koskamp


- Original Message -
From: Stout, Joel R <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, April 24, 2001 10:20 PM
Subject: [beginner] file parsing question


> Sorry so lengthy but here goes:
>
> I am a Perl newbie and trying to parse a file.  Depending on the tags in
the
> data I want to parse each line a different way.  I built the following
> program to test my process.
>
> use strict;
> my (@lines, $testln, @REFln);

What is @lines for? Is doesnt seem to be used.
And @REFln could be declared inside sub parseREF; where $testln is better
declared locally in sub testType.
It might also be more efficient to read the file one time and then process
it
try this:

#!perl

my @lines = (<>);
foreach $line (@lines) {
chomp $line;
my ($element1, $element2, $element3) = split (/\*/, $line, 3);
if ($element1 eq 'REF' && !($element2 eq 'SN')) {
print "Not a Shipment Number, $element1 type $line.\n";
   } else {
print "I found a $element1 line: $line\n";
   }
}




>
> while (<>) {
> chomp;
> testType ($_);
> }
>
> sub testType {
> $testln = $_[0];
> if (/^REF/) {
> print "I found a REF line: $testln\n";
> parseRef ($testln);
> } elsif (/^NTE/) {
> print "I found a NTE line: $testln\n";
> }
> }
>
> sub parseREF {
> print "Parsing line: $_[0]\n";
>
> @REFln = split (/\*/, $_[0]);
>
> print "Element 1) $REFln[0] ";
> print " 2) $REFln[1] ";
> print " 3) $REFln[2]\n";
>
> if ($REFln[1] = "SN") {
> print "$REFln[1]: $REFln[2]\n";
> } else {
> print "Not a Shipment Number, $REFln[1] type line.\n";
> }
> }
>
> Based on the input:
> CUR**USD
> REF*SN*0108106
> REF*PO*cn190108106
> REF*BL*cn190108106
> REF*PS*JessupPA
>
> I expected to see "SN: 0108106" (which I did) but I didn't expect to see
> "SN: cn190108106" and "SN: cn190108106", "SN: JessupPA".
> I expected to see "Not a Shipment Number, PO/BL/PS  type line." for those.
> It almost seems like $REFln[1] is not being refreshed each time parseREF
> happens.
>
> I have written this same program in VB but I'm trying to do my parsing in
> Perl now .  To tell you the truth I really don't have a clue why this
> doesn't work, so any help is much appreciated.
>
> Joel
>




RE: sysread and buffering

2001-04-24 Thread Nic LAWRENCE

Woah! Perl has a getc() function?!! /me goes to look it up! :) Schwing!

> -Original Message-
> From: Sean O'Leary [mailto:[EMAIL PROTECTED]]
> Sent: 24 April 2001 10:16
> To: [EMAIL PROTECTED]
> Subject: Re: sysread and buffering
>
...
>
> But all that's moot, considering that Perl has getc(), and will use your
> system's if it can find it.  But bear in mind, doing this you are
> bypassing
> a lot of Perl's IO niceness, and will have to handle stuff that you don't
> need to handle anyway.
...
> Thank you for your time,
>
> Sean.
>




Re: sysread and buffering

2001-04-24 Thread Paul


--- Sean O'Leary <[EMAIL PROTECTED]> wrote:
> At 10:27 AM 4/24/2001, you wrote:
> > Another possible solution is to use Brian Ingerson's Inline.pm and
> > code the reads &c. with C's lower level IO. I think a C getc()
would 
> > do it
> >
> > But be warned that, while it's actually quite friendly, a raw
> > beginner might have some trouble with the Inline stuff, especially
> > if they don't know C. I'd say look, maybe try, and decide based on
> > your own confidence.
> >
> >Good luck.
> 
> Whoa there, Cowboy!  : )

Yee-ha! lol!

> Inline is way cool, but it's not even really stable yet. 

Mine's been stable as a rock. Never occurred to me it wasn't.
Have to keep that in mind.

> I mess around with it (when I want to be in awe of infinitely
superior
> programming prowess) but I don't think that people just getting into
> Perl want to be worrying about things like finding the right .h file
> that defines their system's getc function, and other such
shenanigans. 

Er? Again, guilty, never occurred to me.
That is, however, why I put in the caveat to people who don't know C.
(See above)

> Plus, a lot of people here might not even have a C compiler. 

Again, see above caveat.
For those of you who might have been confused by this, my apologies.

> (Remember, us Win32 punks usually have to pay some bucks for a good
> one, or have to be compiler gurus ourselves to get GCC set up.)

lol!! True enough.

> But all that's moot, considering that Perl has getc(), and will use
> your system's if it can find it.  

Not on mine. Perl's getc() on this system requires that there be
something in the buffer, which there isn't until you put in a newline.
Screwy design, but it's what we got. =o)

> But bear in mind, doing this you are bypassing a lot of Perl's IO
> niceness, and will have to handle stuff that you don't need to handle
> anyway.

AMEN! (and no sarcasm intended!)

> And it will break when you move the program somewhere else, or if you
> decide you need to read Unicode or something.

Again, agreed!

> So, I guess my point is, this is a solution, and TMTOWTDI, but
> there's a pretty high bar to being able to implement this, not to
> mention that I can't think of a really good reason to do it, beyond
> hubris, which usually isn't a very good reason.

Because on some systems it would work, and the person might have no
interest in portability. If all they want is for their code to work,
and they *do* have a good compiler and familiarity with C, it's one
possible solution (I'm not familiar with ReadTerm). I've written some
horrible code before just because nothing else I tried worked. Also,
since you mention win32, remember Perl's extended motto for windoze:
There's more than one way to do it, and for Windoze that's a good
thing, 'cause lot's of them don't work! ~lol~

Still, I was aware that it was an unlikely solution. I just posted it
because it was the possibility I could come up with that might work on
the system *I'm* using. (I'll have to look at ReadTerm, though.)

> I guess since this is a beginner's list we should try to keep the
> ideas simple, flexible, and reliable.

Duly chastised, I in fact agree. 
 
> I'm not suggesting that I'll always have the right answers.  I've not
> been writing Perl very long, and am discovering new stuff daily.  I
> also have an admittedly limited background in computer programming.  
> But I think your suggestion here isn't really a good one for a
> beginner, seeing as there is a simpler way to the exact same
> functionality ( Perl's own getc() )

Which doesn't work on my box

> and even that is harder to use than the module.  Frankly, I was kinda
> scared of the code put around getc() in the examples, and 
> Anyway, I just think we should keep advice (because that is really
> what we are offering here) as generally useful and easy to follow as 
> possible.  Just my $0.02.

As valid as anyone's opinion, and admirably stated, if a touch long.
~smirk~

Keep up the good work, Sean, and keep me straight. ;o]
Better to make a fool of me for a day than to have possibly lots of
people spending many days working under the onus of bad advice I might
have given. 

Paul

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Global symbol requires explicit pack name

2001-04-24 Thread Kailash . Subramanian



All,
 When I use strict function, I get an error in the following code.
#!/usr/local/bin/perl
use strict ;
my @vob_list = `cleartool lsvob | grep "*"`;
my $entry ;
foreach $entry (@vob_list) {
chomp $entry;
my @fields = split /\s+/, $entry;
my $tag_list ;
my $vbs_list ;
@tag_list = @fields[1] ;
@vbs_list = @fields[2] ;
foreach $lock (@tag_list) {
print "$lock \n" ;
foreach $tardir (@vbs_list) {
print "$tardir \n" ;
}
}
}

Global symbol "tag_list" requires explicit package name at ./back.pl line 10.
Global symbol "vbs_list" requires explicit package name at ./back.pl line 11.
Global symbol "lock" requires explicit package name at ./back.pl line 12.
Variable "@tag_list" is not imported at ./back.pl line 12.
Global symbol "tag_list" requires explicit package name at ./back.pl line 12.
Variable "$lock" is not imported at ./back.pl line 13.
Global symbol "lock" requires explicit package name at ./back.pl line 13.
Global symbol "tardir" requires explicit package name at ./back.pl line 14.
Variable "@vbs_list" is not imported at ./back.pl line 14.
Global symbol "vbs_list" requires explicit package name at ./back.pl line 14.
Variable "$tardir" is not imported at ./back.pl line 15.
Global symbol "tardir" requires explicit package name at ./back.pl line 15.
Execution of ./back.pl aborted due to compilation errors.

I get this error only when I use the strict function, so I figured that this is
not an efficient code. Can somebody help me on this ?

Thx in advance
Kailash





Re: Passing data arguments via command line

2001-04-24 Thread David H. Adler

On Tue, Apr 24, 2001 at 06:52:02AM -0500, Steve Neu wrote:
> > perl myscript.pl "data1" "data2 "data3"
> >
> > (a) is it possible to pass data arguments via the command line in this
> way?
> 
[snip options] 
> -or-
> 
> my ($username, $password, $logfile, $filename) = @ARGV
>  # Expect 4 arguments
>  # Ignore the rest for now

Note, of course, that this does not actually *remove* the first four
arguments from @ARGV.

dha

-- 
David H. Adler - <[EMAIL PROTECTED]> - http://www.panix.com/~dha/
"I go where I will and I do what I can" - Henry Fool



are there any binaries for OS/2

2001-04-24 Thread Calin Popa

Hi, are there ani perl5 binaries for OS/2 Warp?

=
Calin

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Re: sysread and buffering

2001-04-24 Thread Sean O'Leary

At 10:27 AM 4/24/2001, you wrote:
>Another possible solution is to use Brian Ingerson's Inline.pm and code
>the reads &c. with C's lower level IO. I think a C getc() would do
>it
>
>But be warned that, while it's actually quite friendly, a raw beginner
>might have some trouble with the Inline stuff, especially if they don't
>know C. I'd say look, maybe try, and decide based on your own
>confidence.
>
>Good luck.

Whoa there, Cowboy!  : )

Inline is way cool, but it's not even really stable yet.  I mess around 
with it (when I want to be in awe of infinitely superior programming 
prowess) but I don't think that people just getting into Perl want to be 
worrying about things like finding the right .h file that defines their 
system's getc function, and other such shenanigans.  Plus, a lot of people 
here might not even have a C compiler.  (Remember, us Win32 punks usually 
have to pay some bucks for a good one, or have to be compiler gurus 
ourselves to get GCC set up.)

But all that's moot, considering that Perl has getc(), and will use your 
system's if it can find it.  But bear in mind, doing this you are bypassing 
a lot of Perl's IO niceness, and will have to handle stuff that you don't 
need to handle anyway.  And it will break when you move the program 
somewhere else, or if you decide you need to read Unicode or something.

So, I guess my point is, this is a solution, and TMTOWTDI, but there's a 
pretty high bar to being able to implement this, not to mention that I 
can't think of a really good reason to do it, beyond hubris, which usually 
isn't a very good reason.  I guess since this is a beginner's list we 
should try to keep the ideas simple, flexible, and reliable.

I'm not suggesting that I'll always have the right answers.  I've not been 
writing Perl very long, and am discovering new stuff daily.  I also have an 
admittedly limited background in computer programming.  But I think your 
suggestion here isn't really a good one for a beginner, seeing as there is 
a simpler way to the exact same functionality ( Perl's own getc() ) and 
even that is harder to use than the module.  Frankly, I was kinda scared of 
the code put around getc() in the examples, and

Anyway, I just think we should keep advice (because that is really what we 
are offering here) as generally useful and easy to follow as 
possible.  Just my $0.02.

Thank you for your time,

Sean.




Re: if file does not exist create it.

2001-04-24 Thread Paul


--- Peter Lemus <[EMAIL PROTECTED]> wrote:
> I'm writing a script that will read a file, the data
> on the file are directories in a win2k server.  I
> would like to test if the folder exists and create the
> folder if it doesn't exist.  Please give me an example
> of how I can accomplish this.

 open FOO, ">>$file" or die $!; # create if not there
 open FOO,$file  or die $!; # open to read

The first open is an append, which will create the file if it's there,
but won't harm it if it's not. The second open is a read-only, but
causes an implicit close on FOO before reopening it. Then just process
it accordingly.

There are myriad ways to do this, but I prefer this one, as it only
adds one line to your program (the appending open), doesn't require any
modules, etc. You could always add a close FOO; statement, but the 2nd
open does that, and the 2 open() statements immediately together tends
to draw attention.

On the other hand, you called it a folder. More explicit and possibly
more circumstantially correct code:

 mkdir $folder unless -e $folder and -d _;

this creates directory $folder unless it already exists as a directory.
To be cleaner:

 unless (-e $folder) {
   mkdir $folder;
 } else {
   die "$folder not a directory!" unless -d _;
 }

Then (assuming you're reading the directory info),

  opendir DIR, $folder or die $!;

Then readdir to get your data.

As always,
Hope that helps.

Paul


__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Re: More Help: Complex Regex

2001-04-24 Thread Johnathan Kupferer

There's already a lot of good advice here, but just one more thing...

Some people write HTML code like this



Using:
s/<.*?>//g

Doesn't account for that and it won't match.

To allow '.' to match line breaks in tags, use:

  s/<.*?>//gs
- Johnathan




Help on lib/modules Please!!

2001-04-24 Thread Arante, Susan

I had a pm that used to be working and is called using "use ABC::Test;".  I
deleted (for some stupid reasons) the perl directory and didn't realize I
also deleted the ABC subdirectory below site\lib.  I took another copy from
another machine and placed it back under site\lib but now I'm getting this
error message when I try to do "use ABC::Test;" - on Perl 5.  Any ideas?  

Can't locate loadable object for module ABC::Test in @INC (@INC contains:
c:/perl/lib c:/perl/site/lib .) at - line 1



if file does not exist create it.

2001-04-24 Thread Peter Lemus

Hi Guys,

I'm writing a script that will read a file, the data
on the file are directories in a win2k server.  I
would like to test if the folder exists and create the
folder if it doesn't exist.  Please give me an example
of how I can accomplish this.

Regards,
Peter 

=
Peter Lemus
Computer Networks Engineer
[EMAIL PROTECTED]
My Dad always tought me; when you do good; expect to receive good; when you do bad; 
expect the bad...sooner or later.

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Re: [beginner] file parsing question

2001-04-24 Thread Paul


--- Timothy Kimball <[EMAIL PROTECTED]> wrote:
> Ah, yes, one of the most frustrating bugs in the world:
> : if ($REFln[1] = "SN") {
> This *assigns* the value "SN" to $REFln[1]. What you want to do is
> *test* it. String comparisons in Perl are done with "eq" (and numeric
> comparisons with "=="). So you want this:
>   if ($REFln eq "SN") {

> You can avoid this by always writing comparisons with the constant
> (if there is one) on the left-hand side:
> 
>   if ("SN" eq $REFln)
> 
> but I rarely see people actually do that.

People rarely do it, btu I *HIGHLY* recommend it.
This way, if you write 
  if ("SN" = $REFln) {
the compiler will shut down and warn you that you can't *do* that, and
you'll probably say "Oh! that should have been ==, or maybe eq"

It's just cleaner code. =o)


__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Re: More Help: Complex Regex

2001-04-24 Thread David M. Lloyd

On Tue, 24 Apr 2001 [EMAIL PROTECTED] wrote:

> Thank you very much for all the great help I received earlier on extracting
> numbers from text.  There is only one thing I forgot about:
> 
> Some of the files have HTML headers and footers.  I don't want any data
> inside HTML brackets.   I tried:
> 
>   s/<*>//g; 
> 
> I don't understand why this doesn't work. 

This regular expresssion would read, "Zero or more '<' characters followed
by exactly one '>' character".  The '*' actually means, "The character
that came before this '*' will be matched zero or more times".  If you
want to strip out HTML tags, you'll want to do this:

s/<.*?>//g;

There's two differences here.  The first is the addition of the period
(".") which means, match one character, no matter what it is.  The second
is the question mark after the '*' which means, "Grab the fewest number of
characters I can that still satisfies the match".  This prevents the
substitution from gobbling up everything between the very first < and the
very last >.

One other way to write this is like this:

s/<[^>]+>//g;

Here, you say, Match any string that:

1. Starts with < (This is represented by < in the expression)
2. Consists of one or more non-">" character (This is represented by [^>]+
in the expression)
3. Followed by one >

This is the way I'd do it; it's much more straightforward (at least to
me).

- D

<[EMAIL PROTECTED]>




Re: More Help: Complex Regex

2001-04-24 Thread Timothy Kimball


: Try s/<.*>//g - the . means "any character" and will eliminate a
: less-than, then 0 or more characters, then a greater than.

Careful: if there's more than one greater-than in the line, this regex
will wipe out everything between (and including) the first "<" and the
last ">" on the line, because Perl matches are greedy by default. For
example, in this line,

foo

the regex will delete everything from the first "<" in "" in "/a>".

If, on the other hand you direct the regex to match the shortest line
("<.*?>"), then it will wipe out only the tags and leave the text.

(Probably should have expanded on that in my last post.)
--
Tim Kimball · ACDSD / MAST¦ 
Space Telescope Science Institute ¦ We are here on Earth to do good to others.
3700 San Martin Drive ¦ What the others are here for, I don't know.
Baltimore MD 21218 USA¦   -- W.H. Auden




Re: [beginner] file parsing question

2001-04-24 Thread Paul Johnson

On Tue, Apr 24, 2001 at 04:33:00PM -0400, Timothy Kimball wrote:

> You can avoid this by always writing comparisons with the constant
> (if there is one) on the left-hand side:
> 
>   if ("SN" eq $REFln)
> 
> but I rarely see people actually do that.

I think that's because it feels so unnatural and looks so ugly ;-)

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net



Re: More Help: Complex Regex

2001-04-24 Thread Paul


--- [EMAIL PROTECTED] wrote:
> Thank you very much for all the great help I received earlier on
> extracting numbers from text.  There is only one thing I forgot
about:
> Some of the files have HTML headers and footers.  I don't want any
> data inside HTML brackets.   I tried:
>   s/<*>//g; 
> I don't understand why this doesn't work. I actually just need
> s/<*\d*>//g because the other expressions are automatically taken
> care of by the expressions that delete all text.  Why doesn't the
> above work for removing html tags?  I have several perl books and
> none say the character "<" is reserved. "\<" doesn't work either
> Thanks for any help.  (Actually, thanks for writing my program for
> me; although I'm trying hard to do it myself.)   ;-)

First,
>   s/<*>//g; 

this means remove all >'s preceded by any number of >'s.
try this:
 s/<[^>]*>//g;

which gets <, any number of NOT >'s, and a >.

You *could* have said 
   s/<.*>//g; 

The "." being a regex wildcard, but for " a 123 b " it would
grab the whole line. Instead, you could say  s/<.*?>//g which tries to
match a minimal length string (because of the question mark).



__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Re: [beginner] file parsing question

2001-04-24 Thread Kevin Meltzer

Hi Joel,

Did you type this in by hand? :) 

>   parseRef ($testln);
> sub parseREF {

You would want to change one of those! Anyways..

Your problem is in this line:

>   if ($REFln[1] = "SN") {

= is for assignments. You want this to be:

if ($REFln[1] eq "SN") {

To learn more about perl operators like eq, =, and == (which is for numeric
comparisons, while eq is for strings) read the perlop manual page.

Cheers,
Kevin

On Tue, Apr 24, 2001 at 08:20:59PM -, Stout, Joel R ([EMAIL PROTECTED]) 
spew-ed forth:
> Sorry so lengthy but here goes:
> 
> I am a Perl newbie and trying to parse a file.  Depending on the tags in the
> data I want to parse each line a different way.  I built the following
> program to test my process. 
> 
> use strict;
> my (@lines, $testln, @REFln);
> 
> while (<>) {
>   chomp;
>   testType ($_);
> }
> 
> sub testType {
>   $testln = $_[0];
>   if (/^REF/) {
>   print "I found a REF line: $testln\n";
>   parseRef ($testln);
>   } elsif (/^NTE/) {
>   print "I found a NTE line: $testln\n";
>   }
> }
> 
> sub parseREF {
>   print "Parsing line: $_[0]\n";
>   
>   @REFln = split (/\*/, $_[0]);
>   
>   print "Element 1) $REFln[0] ";
>   print " 2) $REFln[1] ";
>   print " 3) $REFln[2]\n";
>   
>   if ($REFln[1] = "SN") {
>   print "$REFln[1]: $REFln[2]\n";
>   } else {
>   print "Not a Shipment Number, $REFln[1] type line.\n";
>   }
> }
> 
> Based on the input:
> CUR**USD
> REF*SN*0108106
> REF*PO*cn190108106
> REF*BL*cn190108106
> REF*PS*JessupPA
> 
> I expected to see "SN: 0108106" (which I did) but I didn't expect to see
> "SN: cn190108106" and "SN: cn190108106", "SN: JessupPA".  
> I expected to see "Not a Shipment Number, PO/BL/PS  type line." for those.  
> It almost seems like $REFln[1] is not being refreshed each time parseREF
> happens.
> 
> I have written this same program in VB but I'm trying to do my parsing in
> Perl now .  To tell you the truth I really don't have a clue why this
> doesn't work, so any help is much appreciated.
> 
> Joel
> 

Writing CGI Applications with Perl - http://perlcgi-book.com
-- 
Nuclear explosions under the Nevada desert? What the f*ck are we testing for?
We already know the sh*t blows up.
-- Frank Zappa



Re: [beginner] file parsing question

2001-04-24 Thread Timothy Kimball


Ah, yes, one of the most frustrating bugs in the world:

:   if ($REFln[1] = "SN") {

This *assigns* the value "SN" to $REFln[1]. What you want to do is
*test* it. String comparisons in Perl are done with "eq" (and numeric
comparisons with "=="). So you want this:

if ($REFln eq "SN") {

You can avoid this by always writing comparisons with the constant
(if there is one) on the left-hand side:

if ("SN" eq $REFln)

but I rarely see people actually do that.
--

Tim Kimball · ACDSD / MAST¦ 
Space Telescope Science Institute ¦ We are here on Earth to do good to others.
3700 San Martin Drive ¦ What the others are here for, I don't know.
Baltimore MD 21218 USA¦   -- W.H. Auden



Re: More Help: Complex Regex

2001-04-24 Thread Curtis Jewell

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Tue, 24 Apr 2001 [EMAIL PROTECTED] wrote:

> Thank you very much for all the great help I received earlier on extracting
> numbers from text.  There is only one thing I forgot about:
>
> Some of the files have HTML headers and footers.  I don't want any data
> inside HTML brackets.   I tried:
>
>   s/<*>//g;

Try perl -e '$x = ">x"; $x =~ s/<*>//g; print $x . "\n"'

It prints out "x".

Your regex will match strings like <>, <<>, <<<>. (i.e. multiple
less-thans followed by a greater-than) because the * applies to the
less-than symbol immediately before it.

Try s/<.*>//g - the . means "any character" and will eliminate a
less-than, then 0 or more characters, then a greater than.

- --Curtis

> I don't understand why this doesn't work. I actually just need s/<*\d*>//g
> because the other expressions are automatically taken care of by the
> expressions that delete all text.  Why doesn't the above work for removing
> html tags?  I have several perl books and none say the character "<" is
> reserved. "\<" doesn't work either.
>
> Thanks for any help.  (Actually, thanks for writing my program for me;
> although I'm trying hard to do it myself.)   ;-)

- -- 
Curtis Jewell  http://curtis.livejournal.com/
[EMAIL PROTECTED]  http://web.missouri.edu/~csjc05/
[EMAIL PROTECTED] http://new-york.utica.mission.net/
Public Key: http://web.missouri.edu/~csjc05/curtis.key.txt

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE65eISNGcErwayIw4RAiMqAJ9vzuLOMP7q6s+GzSYp/EpA/hmxSwCfdhCx
6XHvnzKseahRIpFcMITuFWI=
=9X1p
-END PGP SIGNATURE-




[beginner] file parsing question

2001-04-24 Thread Stout, Joel R

Sorry so lengthy but here goes:

I am a Perl newbie and trying to parse a file.  Depending on the tags in the
data I want to parse each line a different way.  I built the following
program to test my process. 

use strict;
my (@lines, $testln, @REFln);

while (<>) {
chomp;
testType ($_);
}

sub testType {
$testln = $_[0];
if (/^REF/) {
print "I found a REF line: $testln\n";
parseRef ($testln);
} elsif (/^NTE/) {
print "I found a NTE line: $testln\n";
}
}

sub parseREF {
print "Parsing line: $_[0]\n";

@REFln = split (/\*/, $_[0]);

print "Element 1) $REFln[0] ";
print " 2) $REFln[1] ";
print " 3) $REFln[2]\n";

if ($REFln[1] = "SN") {
print "$REFln[1]: $REFln[2]\n";
} else {
print "Not a Shipment Number, $REFln[1] type line.\n";
}
}

Based on the input:
CUR**USD
REF*SN*0108106
REF*PO*cn190108106
REF*BL*cn190108106
REF*PS*JessupPA

I expected to see "SN: 0108106" (which I did) but I didn't expect to see
"SN: cn190108106" and "SN: cn190108106", "SN: JessupPA".  
I expected to see "Not a Shipment Number, PO/BL/PS  type line." for those.  
It almost seems like $REFln[1] is not being refreshed each time parseREF
happens.

I have written this same program in VB but I'm trying to do my parsing in
Perl now .  To tell you the truth I really don't have a clue why this
doesn't work, so any help is much appreciated.

Joel




Re: More Help: Complex Regex

2001-04-24 Thread Timothy Kimball


: Some of the files have HTML headers and footers.  I don't want any data
: inside HTML brackets.   I tried:
: 
:   s/<*>//g; 
: 
: I don't understand why this doesn't work.

Because (a) "<*" in a regex means "zero or more less-thans", and (b)
Perl regex matching is greedy- it matches the longest string that can
make the match true. What you want to do is something like this:

s/<.*?>//g;

In this one, ".*" means "zero or more of anything, which under normal
circumstances would mean > as well, except that ".*?" means "match the
shortest string that makes the regex true".  So "<.*?>" will match the
shortest string between < and >.

Alternatively, you could do this:

s/<[^>]*>//g;

which says "match a <, followed by zero or more characters that aren't
>, and then a >". I think the first looks clearer, but the second sounds
more obvious.

: Thanks for any help.  (Actually, thanks for writing my program for me;
: although I'm trying hard to do it myself.)   ;-)

oh... in that case, ignore everything we've said. ;)
--
Tim Kimball · ACDSD / MAST¦ 
Space Telescope Science Institute ¦ We are here on Earth to do good to others.
3700 San Martin Drive ¦ What the others are here for, I don't know.
Baltimore MD 21218 USA¦   -- W.H. Auden



More Help: Complex Regex

2001-04-24 Thread Allen_Gregg

Thank you very much for all the great help I received earlier on extracting
numbers from text.  There is only one thing I forgot about:

Some of the files have HTML headers and footers.  I don't want any data
inside HTML brackets.   I tried:

  s/<*>//g; 

I don't understand why this doesn't work. I actually just need s/<*\d*>//g
because the other expressions are automatically taken care of by the
expressions that delete all text.  Why doesn't the above work for removing
html tags?  I have several perl books and none say the character "<" is
reserved. "\<" doesn't work either.

Thanks for any help.  (Actually, thanks for writing my program for me;
although I'm trying hard to do it myself.)   ;-)


Gregg R. Allen
EMC 2
Layered Product Engineering
62 TW Alexander Dr
Research Triangle Park, NC. 27709
Phone:  919.248.5859

Blessed are they who expect nothing, 
for they shall not be disappointed.

F. Nietzsche




Re: Random Numbers

2001-04-24 Thread Kevin Meltzer

Hi Sushil,

perldoc -f rand

You can also look at the Math::Random and Math::TrulyRandom modules on the
CPAN.

Cheers,
Kevin

On Tue, Apr 24, 2001 at 02:58:16PM -0700, sushil ([EMAIL PROTECTED]) spew-ed forth:
> Hi ,
> 
> Is there any one who can help me make a randon numer generator
> Any help will be appreciated.
> 
> Thanks
> 
> 
> Sushil Prabhakar
> Cybernet Communications Inc.
> Suite 207
> 20 Amber Street
> Markham, Ontario
> L3R 5P4
> Tel: (905) 947 1801
> Fax:(905) 947 1802
> 

-- 
"As the fletcher whittles and makes straight his arrows, so the master directs
his straying thoughts." 
-- Buddha



Re: @INC variable :please help

2001-04-24 Thread Kevin Meltzer

Hi Rajakumar,

It may be helpful if we knew what failed in  the installation of the
DBD::Oracle module. IMO, it would be better to fix that problem than copy over
another perl installation. 

However, you can change what is in @INC if you want to try that. You can:

use lib qw(/some/path /some/other/path);

At the begining of your script to prepend directories to @INC. Or, you can
set a PERL5LIB environment variable, which will do the same. So, you may want
to add the needed paths in one of those ways, or try to find (and remedy) the
reason why DBD::Oracle won't install for you.

Cheers,
Kevin

On Tue, Apr 24, 2001 at 11:23:23AM -0700, Rajakumar Theja ([EMAIL PROTECTED]) 
spew-ed forth:
> Hi,
> 
> I'm new to perl, so please help.
> My installation of DBD::Oracle for Oracle 8.1.6
> failed.
> After reaching a dead end and not getting any help
> from 
> dbi-users, I decided to copy over a previous
> installation of the perl directory tree which
> includes DBI and DBD from another machine. But this 
> doesn't work, seems like @INC gets set during the
> installation phase and so contains the paths to the
> local perl installation on the previous machine. Can I
> change this to work on the new machine? Or will this
> copy over not work?
> 
> Thanks and any help is appreciated.
> 
> __
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/
> 

-- 
Children are naive -- they trust everyone. School is bad enough, but, if you
put a child anywhere in the vicinity of a church, you're asking for trouble.
-- Frank Zappa



@INC variable :please help

2001-04-24 Thread Rajakumar Theja

Hi,

I'm new to perl, so please help.
My installation of DBD::Oracle for Oracle 8.1.6
failed.
After reaching a dead end and not getting any help
from 
dbi-users, I decided to copy over a previous
installation of the perl directory tree which
includes DBI and DBD from another machine. But this 
doesn't work, seems like @INC gets set during the
installation phase and so contains the paths to the
local perl installation on the previous machine. Can I
change this to work on the new machine? Or will this
copy over not work?

Thanks and any help is appreciated.

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Random Numbers

2001-04-24 Thread sushil

Hi ,

Is there any one who can help me make a randon numer generator
Any help will be appreciated.

Thanks


Sushil Prabhakar
Cybernet Communications Inc.
Suite 207
20 Amber Street
Markham, Ontario
L3R 5P4
Tel: (905) 947 1801
Fax:(905) 947 1802




Re: Complex Regex.

2001-04-24 Thread Timothy Kimball


Slight correction to my last post:

: my $float_re = qr{
: 
: \d+\.\d+  # Matches "2.3"
:   | \d+\. # Matches "2."
:   |\.=d+  # Matches ".2"
:   | \d+   # Matches "2"
: 
: }x; # "x" means "extended regex syntax"

In the third line of the first regex, "=" should be "\".

-- tdk



Re: Help on Date Format

2001-04-24 Thread Kevin Meltzer

In this case, it wont really matter. Since 1 and "1" is essentially  the same.
If you were actually using a signed integer (in decimal), then you would see
the difference:

>From perldoc -f sprintf:

   %s   a string
   %d   a signed integer, in decimal

[root@fluffhead /]# perl -e 'printf "%04s\n", 12.5'
12.5
[root@fluffhead /]# perl -e 'printf "%04d\n", 12.5'
0012

But, go back to what is basically a string (integer in string context??):

[root@fluffhead /]# perl -e 'printf "%04d\n", 12'
0012
[root@fluffhead /]# perl -e 'printf "%04s\n", 12'
0012

So, why her snippet suddenly freaked out, I don't know. We didn't actually see
what created the $year, $month and $day *shrug*

Cheers,
Kevin

On Tue, Apr 24, 2001 at 11:40:23AM -0500, John Joseph Trammell 
([EMAIL PROTECTED]) spew-ed forth:
> [snip]
> 
> Well I'll be damned.
> 
> [ ~ ] perl -e 'printf "%04s\n", 1'
> 0001
> [ ~ ] perl -e 'printf "%04s\n", "1"'
> 0001
> [ ~ ] perl -e 'printf "%04s\n", "   1"'
>1
> [ ~ ] perl -e 'printf "%04s\n", "  1"'
> 0  1
> [ ~ ]
> 
> And here I thought I knew it all.  :-)

-- 
"This Too Shall Pass"
-- inscription on the inside of King Solomon's Ring.



Re: Complex Regex.

2001-04-24 Thread Timothy Kimball


: I thought I was improving at expressions but this one has me stumped:
: 
: I have text interspersed with numbers.  The text can be anything, including
: all types of punctuation marks.

Well (sound of knuckles cracking), let's see...

I've only been on the list a couple of days, and I've already seen a
couple of questions about regexes matching numbers. I've never found a
slick way to do this- it's too easy to write one that matches an empty
string- so I usually use a more bull-headed approach (we'll use the
extended regular expression syntax, so we can break the regex up over
several lines & include comments):

my $float_re = qr{

  \d+\.\d+  # Matches "2.3"
| \d+\. # Matches "2."
|\.=d+  # Matches ".2"
| \d+   # Matches "2"

}x; # "x" means "extended regex syntax"

while (whatever) {
my @numbersInText = /($float_re)/og;
  # Quiz: What does the above line do? ;)
}

This will match numbers like those in the comments, checking them in
the order that they're listed. Fine, but oops, we're not picking up the
minus signs. So we'll modify it (and throw in plus signs while we're at
it):

  [-+]? \d+\.\d+
| [-+]? \d+\.
| [-+]?\.\d+
| [-+]? \d+

(The spaces don't count as part of the regex in extended mode.) Better,
but 2-4 still is not done as "2 4". So, we need to make sure that the
character just before the minus sign is not a digit, but we don't want
to count it as part of the matched substring.  So, we'll use a
zero-length look-behind assertion:

  (?<=\D) [-+]? \d+\.\d+
| (?<=\D) [-+]? \d+\.
| (?<=\D) [-+]?\.\d+
| (?<=\D) [-+]? \d+

What does "(?<=\D) [-+]? \d+\.\d+" do? It says: Find a non-digit (but
don't include it in the match string), followed possible by either "-"
or "+", and a digit-dot-digit pattern. Assertions take a little getting
used to, but they're powerful stuff (I think even C# has them).

Now that's a lot to type, so we'll do one more trick to clean it up by
factoring out the common stuff and enclosing the rest in (?: ... ),
which groups without leaving anything in a backreference ($1, $2, etc):

my $float_re = qr{
(?<=\D)   # Look for a non-digit, but don't include it
[-+]? # Could have - or +
(?:
\d+\.\d+  # Matches "2.3"
  | \d+\. # Matches "2."
  |\.\d+  # Matches ".3"
  | \d+   # Matches "2"
)
}x;

This regex checks against your example. Hope this helps.

--

Tim Kimball · ACDSD / MAST¦ 
Space Telescope Science Institute ¦ We are here on Earth to do good to others.
3700 San Martin Drive ¦ What the others are here for, I don't know.
Baltimore MD 21218 USA¦   -- W.H. Auden



Re: Complex Regex.

2001-04-24 Thread M.W. Koskamp


- Original Message -
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, April 24, 2001 6:34 PM
Subject: Complex Regex.


> The Text has numbers in it apparently-1.0 at random but 12 actually not...
> $%  12.3   0.9  .333  33 and -33.909  I need to extract
> u&t(y2335.09u see
>
> all the legiti5.33mate integers and floating point numbers and separate
them
> with CRs.  All text and nun-numeric data should be chucked.  it needs to
> look for negative numbers but 2-1 and 4-66.7  are "2  1  4  66.7".   That
is
> - is a delimiter unless there's a space in front in which case the number
is
> negative.
>
> The output for the text above should be:
>
> -1.0
> 12
> 12.3
> 0.9
> .333
> 33
> -33.909
> 2335.09
> 5.33
> 2
> 1
> 4
> 66.7
> 2
> 1
> 2  <- this should be a 4 :-)
> 66.7

I would not try to match all number in 1 expression.
instead you could look for parts that match your criteria and then search
the remainder if the string.
Below is a solution to do this:

while( $text =~ s/(\s+-)?(\d+)(\.\d+)?(.*)//s) {
   print "$1$2$3\n";
   $text = $4||$3;
}

The expression has these parts:

(\s+-)? : optional a whitespace followed by a minus sign
(\d+)   : obligatory one or more digits.
(\.\d+) : optional a dot followed by one or more numbers
(.*) : the rest of the string.

All expressions within brackets will be put in $1 trough $4.
The second sub-expression  will be $2 or $1 (in case there isnt a minus
sign).
So the rest of the string will be $4 or $3.

Maarten.




Re: [BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Paul


Agreed, and thanks for pointing that out!

--- Michael Lamertz <[EMAIL PROTECTED]> wrote:
> Paul ([EMAIL PROTECTED]) wrote:
> > 
> >  #!/usr/local/bin/perl -w
> > 
> >  use strict 
> >  open (FILE,$0) or die $!; # this reads itself
> >  my($data,%count); 
> >  { local $/ = undef;   # erases the record seperator for this
> block
> >$data = ; # slurps in the whole file to $data
> >  }   
> >  close(FILE);  # good habit
> >  map { $count{$_}++ } $data =~ /(\w+)/sog; # watch the context!
> >  print map { "$count{$_} occurances of '$_'\n" } sort keys %count;
> > 
> > Perl is a wonderfully concise language.
> > The above is strictly given as an example of a few performance
> tricks
> > that are worth researching. =o)
> 
> I agree printing the map output, but I disagree using map to
> calculate
> the sums.  map always generates a new array that immediately gets
> dumped
> since it's not assigned.  A foreach would be nicer to system
> resources
> and better to read.  To make it short, use it postfix:
> 
> $count{$_}++ foreach ($data=~ /.../);
> 
> Check 'perldoc perlfaq6' for reference.
> 
> -- 
>  If we fail, we will lose the war.
> 
> Michael Lamertz  | [EMAIL PROTECTED] /
> [EMAIL PROTECTED]
> Nordstr. 49  | http://www.lamertz.net
> 50733 Cologne| Work: +49 221 3091-121
> Germany  | Priv: +49 221 445420 / +49 171 6900 310


__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Re: pulling out part of a /path/to/a/file

2001-04-24 Thread Andy Sharp

hi,

here's a regex that matches what you're after:

$filename =~ m/\/(File-[^\/]+)/;
$part_you_want = $1;

Simply using negation to match "File-" (and anything which is not a "/")
which is preceeded by a "/", is what you want.  The trailing / is
optional.

File::Basename is used to separate the filename into 3 base elements,
the path, the name and the extension.  Since what you're after is part
of the path, using it only adds an unneeded step.

fileparse("/home4/dsad..[sniped]..03/File-11523.1/html/main.htm");

returns 
/home4/dsadmin/7790/DocuShare/documents/b004/File-1156/html/ as the path
main as the name  (base)
.htm as the extension.

Which still leaves you parsing the path for the part you want.

Hope that helps,

--A

"Sandor W. Sklar" wrote:
> 
> Hi, folks ...
> 
> I'm generating a list of files (from a find subroutine) and putting
> them in an array.  The list looks like ...
> 
> /home4/dsadmin/7790/DocuShare/documents/b003/File-11523.1
> /home4/dsadmin/7790/DocuShare/documents/b003/File-11587.1
> /home4/dsadmin/7790/DocuShare/documents/b003/File-11651.1
> /home4/dsadmin/7790/DocuShare/documents/b004/File-1156/html/main.htm
> /home4/dsadmin/7790/DocuShare/documents/b004/File-1604/html/main.htm
> 
> (... a small sample)
> 
> and I'm trying to get just the "File-" part of each line; some
> lines that I am matching against will have a trailing slash, with
> additional path info that I'm not interested in; other lines will
> have a period and a number following, which I am also not interested
> in.
> 
> Perhaps the File::Basename module would do what I want, but I can't
> get my mind around its documentation.  I thought of using split on
> each line (splitting on the "/", and then looking each element of the
> array returned), but that seems, well, stupid.  I'm sure that there
> is some really simple magic here; I just don't see it.  Can someone
> enlighten me please?
> 
> Thanks,
> -s-
> --
> sandor w. sklar
> unix systems administrator
> stanford university itss-css



Re: pulling out part of a /path/to/a/file

2001-04-24 Thread Kevin Meltzer

Ahh yes.. I didn't go down all the examples.. once he said he wanted to use
File::Basename I wouldn't think he wanted anything put the end. Now he knows
how to get the basename as well ;)

Cheers,
Kevin

On Tue, Apr 24, 2001 at 07:19:02PM +0200, Michael Lamertz 
([EMAIL PROTECTED]) spew-ed forth:
> Kevin Meltzer ([EMAIL PROTECTED]) wrote:
> > Just use the basename() method from File::Basename;
> > 
> > # perl -MFile::Basename -e 'print basename("/tmp/foo/003/File-11523.1")';
> > File-11523.1
> 
> That won't help him with this line:
> 
> > > /home4/dsadmin/7790/DocuShare/documents/b004/File-1156/html/main.htm
> 
> Casey's is the way to do it.
> 

-- 
"I know the human being and fish can coexist peacefully."
-- G.W. Bush, Saginaw, MI 09/29/2000



Re: Complex Regex.

2001-04-24 Thread Paul


--- [EMAIL PROTECTED] wrote:
> I thought I was improving at expressions but this one has me stumped:
> 
> I have text interspersed with numbers.  The text can be anything,
> including all types of punctuation marks.
> 
> Well let me give an example:  
> 
> The Text has numbers in it apparently-1.0 at random but 12 actually
> not...
> $%  12.3   0.9  .333  33 and -33.909  I need to extract
> u&t(y2335.09u see
> 
> all the legiti5.33mate integers and floating point numbers and
> separate them
> with CRs.  All text and nun-numeric data should be chucked.  it needs
> to
> look for negative numbers but 2-1 and 4-66.7  are "2  1  4  66.7".  
> That is
> - is a delimiter unless there's a space in front in which case the
> number is
> negative.
> 
> The output for the text above should be:
> 
> -1.0  
> 12
> 12.3
> 0.9
> .333
> 33
> -33.909  
> 2335.09
> 5.33
> 2
> 1
> 4
> 66.7
> 2
> 1
> 2
> 66.7
> 
> Any help on the above would be GREATLY appreciated.  

Okay, I got this to work. 
here's the output:

The text:
 
The Text has numbers in it apparently-1.0 at random but 12 actually
not...
$%  12.3   0.9  .333  33 and -33.909  I need to extract
u&t(y2335.09u see
all the legiti5.33mate integers and floating point numbers and separate

them
with CRs.  All text and nun-numeric data should be chucked.  it needs
to
look for negative numbers but 2-1 and 4-66.7  are "2  1  4  66.7".  
That 
is
- is a delimiter unless there's a space in front in which case the
number 
is
negative.
 
The output:
1.0
12
12.3
0.9
.333
33
-33.909
2335.09
5.33
2
1
4
66.7
2
1
4
66.7

Here's the code:

 use strict;  # good habit
 open (FILE,$ARGV[0]) or die $!;  # as a script, processes first arg
 my($data,$result);  # some working vars
 { local $/ = undef;  # set up to 
   $data = ;# slurp the infile into $data
 }# close the scope of the local()
 close(FILE); # close the arg file
 $result = join "\r\n", $data =~ /((?: -)?\d*[.]?\d+)/sog;
 $result =~ s/^ //omg;# polish out the leading spaces
 print "The text:\n $data \nThe output:\n$result\n";

and the regex elaborated:

 /((?: -)?\d*[.]?\d+)/sog;

First, I check for negatives, which you said would have a
space-and-then-a-minus. I wrap them with a (?:), which doesn't make
another variable, but lets me group them. That way the return should
still be a neat array, but I can say (?: -)?, which means "zero or one
 ' -'s". The space-minus becomes part of the pattern, but
anything-else-minus is ignored. 

The rest of the pattern is simple enough: any number of digits
(including zero) followed by one-or-no decimals, followed by one or
more digits. That gets (using zero for any digit here) 0.0, .0, and 0,
so we've covered 0.0,  -0.0, .0,  -.0, 0, and -0.

The join stacks them with CRLF's between, accomplishing everything but
erasing the leading space on negatives.

 $result =~ s/^ //omg;# polish out the leading spaces

So, we treat $result as multiple lines so that ^ matches after every
newline, and knock off the spaces. Done!

Hope that helps, and feel free to ask questions!

Paul

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Re: pulling out part of a /path/to/a/file

2001-04-24 Thread Michael Lamertz

Kevin Meltzer ([EMAIL PROTECTED]) wrote:
> Just use the basename() method from File::Basename;
> 
> # perl -MFile::Basename -e 'print basename("/tmp/foo/003/File-11523.1")';
> File-11523.1

That won't help him with this line:

> > /home4/dsadmin/7790/DocuShare/documents/b004/File-1156/html/main.htm

Casey's is the way to do it.

-- 
 If we fail, we will lose the war.

Michael Lamertz  | [EMAIL PROTECTED] / [EMAIL PROTECTED]
Nordstr. 49  | http://www.lamertz.net
50733 Cologne| Work: +49 221 3091-121
Germany  | Priv: +49 221 445420 / +49 171 6900 310



Re: Help on Date Format

2001-04-24 Thread John Joseph Trammell

On Tue, Apr 24, 2001 at 01:09:13PM -0400, Kevin Meltzer wrote:
> Hi Susan,
> 
> I get what you expect:
> 
> perl -wle '$y=2001;$m=4;$d=5;printf("\%s%02s%02s.doc",$y,$m,$d)';
> 20010405.doc

[snip]

Well I'll be damned.

[ ~ ] perl -e 'printf "%04s\n", 1'
0001
[ ~ ] perl -e 'printf "%04s\n", "1"'
0001
[ ~ ] perl -e 'printf "%04s\n", "   1"'
   1
[ ~ ] perl -e 'printf "%04s\n", "  1"'
0  1
[ ~ ]

And here I thought I knew it all.  :-)

-- 
Just Another Perl Hacker.



RE: Help on Date Format

2001-04-24 Thread Arante, Susan

Thanks to all your responses.  It works now!!

Kevin, I'll try this one as well, but for now the d instead of s works
enough!!

-Original Message-
From: Kevin Meltzer [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 24, 2001 10:09 AM
To: Arante, Susan
Cc: [EMAIL PROTECTED]
Subject: Re: Help on Date Format


Hi Susan,

I get what you expect:

perl -wle '$y=2001;$m=4;$d=5;printf("\%s%02s%02s.doc",$y,$m,$d)';
20010405.doc

Personally, I like POSIX.pm for dates.

# perl -MPOSIX -wle 'print strftime("%Y%m%d", localtime) . ".doc"';
20010424.doc

'perldoc POSIX' to learn more (look for strftime).

Cheers,
Kevin

On Tue, Apr 24, 2001 at 11:00:40AM -0500, Arante, Susan
([EMAIL PROTECTED]) spew-ed forth:
> Could someone tell me why this is happening?  When I use this command, it
> used to give me 20010405.doc (mmdd.doc), now it's giving me 2001 4
5.doc
> - I'm losing the leading zeros.  
> Command is on Perl 5 - printf("\%s%02s%02s.doc",$year,$month,$day).
> 
> Thanks.
> 

-- 
I write the music I like. If other people like it, fine, they can go buy the
albums. And if they don't like it, there's always Michael Jackson for them
to
listen to. -- Frank Zappa (about his music from the Yellow Shark)



Re: pulling out part of a /path/to/a/file

2001-04-24 Thread Michael Lamertz

Sandor W. Sklar ([EMAIL PROTECTED]) wrote:
> Hi, folks ...
> 
> I'm generating a list of files (from a find subroutine) and putting 
> them in an array.  The list looks like ...
> 
> /home4/dsadmin/7790/DocuShare/documents/b003/File-11523.1
> /home4/dsadmin/7790/DocuShare/documents/b003/File-11587.1
> /home4/dsadmin/7790/DocuShare/documents/b003/File-11651.1
> /home4/dsadmin/7790/DocuShare/documents/b004/File-1156/html/main.htm
> /home4/dsadmin/7790/DocuShare/documents/b004/File-1604/html/main.htm
> 
> (... a small sample)
> 
> and I'm trying to get just the "File-" part of each line; some 
> lines that I am matching against will have a trailing slash, with 
> additional path info that I'm not interested in; other lines will 
> have a period and a number following, which I am also not interested 
> in.

Is there any special reason why you don't regexp your information from
out of the line?

-- 
 If we fail, we will lose the war.

Michael Lamertz  | [EMAIL PROTECTED] / [EMAIL PROTECTED]
Nordstr. 49  | http://www.lamertz.net
50733 Cologne| Work: +49 221 3091-121
Germany  | Priv: +49 221 445420 / +49 171 6900 310



Re: Help on Date Format

2001-04-24 Thread Kevin Meltzer

Hi Susan,

I get what you expect:

perl -wle '$y=2001;$m=4;$d=5;printf("\%s%02s%02s.doc",$y,$m,$d)';
20010405.doc

Personally, I like POSIX.pm for dates.

# perl -MPOSIX -wle 'print strftime("%Y%m%d", localtime) . ".doc"';
20010424.doc

'perldoc POSIX' to learn more (look for strftime).

Cheers,
Kevin

On Tue, Apr 24, 2001 at 11:00:40AM -0500, Arante, Susan 
([EMAIL PROTECTED]) spew-ed forth:
> Could someone tell me why this is happening?  When I use this command, it
> used to give me 20010405.doc (mmdd.doc), now it's giving me 2001 4 5.doc
> - I'm losing the leading zeros.  
> Command is on Perl 5 - printf("\%s%02s%02s.doc",$year,$month,$day).
> 
> Thanks.
> 

-- 
I write the music I like. If other people like it, fine, they can go buy the
albums. And if they don't like it, there's always Michael Jackson for them to
listen to. -- Frank Zappa (about his music from the Yellow Shark)



Re: Help on Date Format

2001-04-24 Thread Casey West

On Tue, Apr 24, 2001 at 11:00:40AM -0500, Arante, Susan wrote:
: Could someone tell me why this is happening?  When I use this command, it
: used to give me 20010405.doc (mmdd.doc), now it's giving me 2001 4 5.doc
: - I'm losing the leading zeros.  
: Command is on Perl 5 - printf("\%s%02s%02s.doc",$year,$month,$day).


Try this:

printf( "%04d%02d%02d", $year, $month, $day );

for printf(), %d is used for integers and integers will be right
padded with zeros, like you want.

See:

perldoc -f printf

Enjoy!

-- 
Casey West



Re: Help on Date Format

2001-04-24 Thread John Joseph Trammell

On Tue, Apr 24, 2001 at 11:00:40AM -0500, Arante, Susan wrote:
> Could someone tell me why this is happening?  When I use this command, it
> used to give me 20010405.doc (mmdd.doc), now it's giving me 2001 4 5.doc
> - I'm losing the leading zeros.  
> Command is on Perl 5 - printf("\%s%02s%02s.doc",$year,$month,$day).

You probably want "%d%02d%02d.doc" as your format string.

 d => digits
 s => strings

And I don't think you need that leading "\".

-- 
Aren't you, at this point, cutting down a California Redwood using a
banana *and* a particle accelerator?
 - Bernard El-Hagin, in CLPM



Re: pulling out part of a /path/to/a/file

2001-04-24 Thread Casey West

On Tue, Apr 24, 2001 at 09:52:04AM -0700, Sandor W. Sklar wrote:
: Hi, folks ...
: 
: I'm generating a list of files (from a find subroutine) and putting 
: them in an array.  The list looks like ...
: 
: /home4/dsadmin/7790/DocuShare/documents/b003/File-11523.1
: /home4/dsadmin/7790/DocuShare/documents/b003/File-11587.1
: /home4/dsadmin/7790/DocuShare/documents/b003/File-11651.1
: /home4/dsadmin/7790/DocuShare/documents/b004/File-1156/html/main.htm
: /home4/dsadmin/7790/DocuShare/documents/b004/File-1604/html/main.htm
: 
: (... a small sample)
: 
: and I'm trying to get just the "File-" part of each line; some 
: lines that I am matching against will have a trailing slash, with 
: additional path info that I'm not interested in; other lines will 
: have a period and a number following, which I am also not interested 
: in.
: 
: Perhaps the File::Basename module would do what I want, but I can't 
: get my mind around its documentation.  I thought of using split on 
: each line (splitting on the "/", and then looking each element of the 
: array returned), but that seems, well, stupid.  I'm sure that there 
: is some really simple magic here; I just don't see it.  Can someone 
: enlighten me please?

Well, if you're just interested in a fast, easy way of doing this,
where you always know that there will be 'File-' and then some
numbers, try:

#!/usr/local/bin/perl -w
use strict;
$|++;

while (  ) {
  my( $part ) = /(File-\d+)/; # In list context ( forced by using
  # parens with my() ), a match will
  # return a list of matches.  In this
  # case, one match.
  print "I like this $part\n";
}

__END__
/home4/dsadmin/7790/DocuShare/documents/b003/File-11523.1
/home4/dsadmin/7790/DocuShare/documents/b003/File-11587.1
/home4/dsadmin/7790/DocuShare/documents/b003/File-11651.1
/home4/dsadmin/7790/DocuShare/documents/b004/File-1156/html/main.htm
/home4/dsadmin/7790/DocuShare/documents/b004/File-1604/html/main.htm


-- 
Casey West



Re: [BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Michael Lamertz

Paul ([EMAIL PROTECTED]) wrote:
> 
>  #!/usr/local/bin/perl -w
> 
>  use strict 
>  open (FILE,$0) or die $!; # this reads itself
>  my($data,%count); 
>  { local $/ = undef;   # erases the record seperator for this block
>$data = ; # slurps in the whole file to $data
>  }   
>  close(FILE);  # good habit
>  map { $count{$_}++ } $data =~ /(\w+)/sog; # watch the context!
>  print map { "$count{$_} occurances of '$_'\n" } sort keys %count;
> 
> Perl is a wonderfully concise language.
> The above is strictly given as an example of a few performance tricks
> that are worth researching. =o)

I agree printing the map output, but I disagree using map to calculate
the sums.  map always generates a new array that immediately gets dumped
since it's not assigned.  A foreach would be nicer to system resources
and better to read.  To make it short, use it postfix:

$count{$_}++ foreach ($data=~ /.../);

Check 'perldoc perlfaq6' for reference.

-- 
 If we fail, we will lose the war.

Michael Lamertz  | [EMAIL PROTECTED] / [EMAIL PROTECTED]
Nordstr. 49  | http://www.lamertz.net
50733 Cologne| Work: +49 221 3091-121
Germany  | Priv: +49 221 445420 / +49 171 6900 310



RE: pulling out part of a /path/to/a/file

2001-04-24 Thread Larry Shatzer

I've done this several ways, depending on my mood.

1.
@path = split(/\//, $file);
$filename = $path[$#path];

2.
$filename = $1 if ($file =~ m|/([^/]+)$|);

3.
use File::Basename;
$filename = basename($file);



1 uses split and $#array, which can be nasty if someone set $[ to something
other than 0, and not very portable


2 Not very portable 

3 best method

-Original Message-
From: Sandor W. Sklar [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 24, 2001 9:52 AM
To: [EMAIL PROTECTED]
Subject: pulling out part of a /path/to/a/file


Hi, folks ...

I'm generating a list of files (from a find subroutine) and putting 
them in an array.  The list looks like ...

/home4/dsadmin/7790/DocuShare/documents/b003/File-11523.1
/home4/dsadmin/7790/DocuShare/documents/b003/File-11587.1
/home4/dsadmin/7790/DocuShare/documents/b003/File-11651.1
/home4/dsadmin/7790/DocuShare/documents/b004/File-1156/html/main.htm
/home4/dsadmin/7790/DocuShare/documents/b004/File-1604/html/main.htm

(... a small sample)

and I'm trying to get just the "File-" part of each line; some 
lines that I am matching against will have a trailing slash, with 
additional path info that I'm not interested in; other lines will 
have a period and a number following, which I am also not interested 
in.


Perhaps the File::Basename module would do what I want, but I can't 
get my mind around its documentation.  I thought of using split on 
each line (splitting on the "/", and then looking each element of the 
array returned), but that seems, well, stupid.  I'm sure that there 
is some really simple magic here; I just don't see it.  Can someone 
enlighten me please?

Thanks,
-s-
-- 
sandor w. sklar
unix systems administrator
stanford university itss-css



Re: pulling out part of a /path/to/a/file

2001-04-24 Thread Kevin Meltzer

Just use the basename() method from File::Basename;

# perl -MFile::Basename -e 'print basename("/tmp/foo/003/File-11523.1")';
File-11523.1


Cheers,
Kevin

On Tue, Apr 24, 2001 at 09:52:04AM -0700, Sandor W. Sklar ([EMAIL PROTECTED]) 
spew-ed forth:
> Hi, folks ...
> 
> I'm generating a list of files (from a find subroutine) and putting 
> them in an array.  The list looks like ...
> 
> /home4/dsadmin/7790/DocuShare/documents/b003/File-11523.1
> /home4/dsadmin/7790/DocuShare/documents/b003/File-11587.1
> /home4/dsadmin/7790/DocuShare/documents/b003/File-11651.1
> /home4/dsadmin/7790/DocuShare/documents/b004/File-1156/html/main.htm
> /home4/dsadmin/7790/DocuShare/documents/b004/File-1604/html/main.htm
> 
> (... a small sample)
> 
> and I'm trying to get just the "File-" part of each line; some 
> lines that I am matching against will have a trailing slash, with 
> additional path info that I'm not interested in; other lines will 
> have a period and a number following, which I am also not interested 
> in.
> 
> 
> Perhaps the File::Basename module would do what I want, but I can't 
> get my mind around its documentation.  I thought of using split on 
> each line (splitting on the "/", and then looking each element of the 
> array returned), but that seems, well, stupid.  I'm sure that there 
> is some really simple magic here; I just don't see it.  Can someone 
> enlighten me please?
> 
> Thanks,
> -s-
> -- 
> sandor w. sklar
> unix systems administrator
> stanford university itss-css
> 

-- 
You think because you understand _one_ you must understand two. Because
one and one make _two_. But you must also understand _and_.
--Sufi Sage



Help on Date Format

2001-04-24 Thread Arante, Susan

Could someone tell me why this is happening?  When I use this command, it
used to give me 20010405.doc (mmdd.doc), now it's giving me 2001 4 5.doc
- I'm losing the leading zeros.  
Command is on Perl 5 - printf("\%s%02s%02s.doc",$year,$month,$day).

Thanks.



Re: [BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Kevin Meltzer

Hi Chris,

You are getting only the last line of the file because of this:

> foreach $i (@lines) {
> @words = split(/\s+/, $i);
> }

You reassign the @words array each time, and end up with the last line only
when exiting the foreach loop. You may want to look at 'perldoc -f push' to see
how to add to an array.

Here is how I would likely accomplish  this task:

#!/usr/bin/perl -w 

use strict;
my %counts;

open(FILE,"file.txt") or die "Can't open file: $!";
my @lines = ;
close FILE;

for (@lines) {
$counts{$_}++ for (split /\s+/);
}

print qq{$counts{$_} occurances of the word $_\n} for keys %counts;


Cheers,
Kevin

On Tue, Apr 24, 2001 at 10:17:02AM -0500, Chris Brown ([EMAIL PROTECTED]) spew-ed 
forth:
> so...this is suposed to count the words in FILE and return how many occourances of 
>each word there were...its not working for me thoughits only returning the count 
>for the last word in the file...help
> 
> #!/usr/local/bin/perl
> 
> open (FILE,"../www/main.php3");
> @lines=;
> close(FILE);
> 
> foreach $i (@lines) {
> @words = split(/\s+/, $i);
> }
> 
> foreach $word (@words) {
> $wordcount{"$word"}=0;
> }
> 
> foreach $word2 (@words) {
> $wordcount{"$word2"}+=1;
> }
> 
> foreach $key (keys (%wordcount)) {
> print "$wordcount{$key} occourances of the whord $key\n";
> }
> 

-- 
Down that path lies madness.  On the other hand, the road to hell is
paved with melting snowballs. 
--Larry Wall in <[EMAIL PROTECTED]>



pulling out part of a /path/to/a/file

2001-04-24 Thread Sandor W. Sklar

Hi, folks ...

I'm generating a list of files (from a find subroutine) and putting 
them in an array.  The list looks like ...

/home4/dsadmin/7790/DocuShare/documents/b003/File-11523.1
/home4/dsadmin/7790/DocuShare/documents/b003/File-11587.1
/home4/dsadmin/7790/DocuShare/documents/b003/File-11651.1
/home4/dsadmin/7790/DocuShare/documents/b004/File-1156/html/main.htm
/home4/dsadmin/7790/DocuShare/documents/b004/File-1604/html/main.htm

(... a small sample)

and I'm trying to get just the "File-" part of each line; some 
lines that I am matching against will have a trailing slash, with 
additional path info that I'm not interested in; other lines will 
have a period and a number following, which I am also not interested 
in.


Perhaps the File::Basename module would do what I want, but I can't 
get my mind around its documentation.  I thought of using split on 
each line (splitting on the "/", and then looking each element of the 
array returned), but that seems, well, stupid.  I'm sure that there 
is some really simple magic here; I just don't see it.  Can someone 
enlighten me please?

Thanks,
-s-
-- 
sandor w. sklar
unix systems administrator
stanford university itss-css



RE: failure notice

2001-04-24 Thread Jonathan Kerr

When subscribing to a new group, it's good practice to hang on to the
"welcome to the group" email that the list server sends you with all the
useful information, like how to unsubscribe.  In any case, here's what mine
says:

 To remove your address from the list, just send a message to
 the address in the ``List-Unsubscribe'' header of any list
 message. If you haven't changed addresses since subscribing,
 you can also send a message to:
<[EMAIL PROTECTED]>

J.

-Original Message-
From: Collins, Eric S. [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 24, 2001 9:27 AM
To: [EMAIL PROTECTED]
Subject: RE: failure notice


How do I remove this mailing list from my account? This e-mail account can't
receive the massive amounts of mail which this list generates.

Thanks,
Eric



Complex Regex.

2001-04-24 Thread Allen_Gregg

I thought I was improving at expressions but this one has me stumped:

I have text interspersed with numbers.  The text can be anything, including
all types of punctuation marks.

Well let me give an example:  

The Text has numbers in it apparently-1.0 at random but 12 actually not...
$%  12.3   0.9  .333  33 and -33.909  I need to extract
u&t(y2335.09u see

all the legiti5.33mate integers and floating point numbers and separate them
with CRs.  All text and nun-numeric data should be chucked.  it needs to
look for negative numbers but 2-1 and 4-66.7  are "2  1  4  66.7".   That is
- is a delimiter unless there's a space in front in which case the number is
negative.

The output for the text above should be:

-1.0
12
12.3
0.9
.333
33
-33.909  
2335.09
5.33
2
1
4
66.7
2
1
2
66.7

Any help on the above would be GREATLY appreciated.  

Thanks,

Gregg R. Allen
EMC 2
Layered Product Engineering
62 TW Alexander Dr
Research Triangle Park, NC. 27709
Phone:  919.248.5859

Blessed are they who expect nothing, 
for they shall not be disappointed.

F. Nietzsche




Re: failure notice

2001-04-24 Thread Casey West

On Tue, Apr 24, 2001 at 11:26:59AM -0500, Collins, Eric S. wrote:
: How do I remove this mailing list from my account? This e-mail account can't
: receive the massive amounts of mail which this list generates.

I'm sorry to hear that.

http://lists.perl.org/showlist.cgi?name=beginners

-- 
Casey West



RE: failure notice

2001-04-24 Thread Collins, Eric S.

How do I remove this mailing list from my account? This e-mail account can't
receive the massive amounts of mail which this list generates.

Thanks,
Eric



Re: PERL Software Installation

2001-04-24 Thread Dan Brown

Go to

http://www.perl.com/

and click on the "Download" link in nav bar on the left-hand side of the
screen.  Then read the instructions.


Saritha_Vinod wrote:
> 
> Hi
> 
> Kindly advice me how to install Perl Software in the below Operating
> Systems:
> 1. Linux
> 2. Windows 98
> 
> Thanks,
> SV



Re: [BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Paul


--- Chris Brown <[EMAIL PROTECTED]> wrote:
> so...this is suposed to count the words in FILE and return how many
> occourances of each word there were...its not working for me
> thoughits only returning the count for the last word in the
> file...help
> 
> #!/usr/local/bin/perl
> 
> open (FILE,"../www/main.php3");
> @lines=;
> close(FILE);
> 
> foreach $i (@lines) {
> @words = split(/\s+/, $i);
> }
> 
> foreach $word (@words) {
> $wordcount{"$word"}=0;
> }
> 
> foreach $word2 (@words) {
> $wordcount{"$word2"}+=1;
> }
> 
> foreach $key (keys (%wordcount)) {
> print "$wordcount{$key} occourances of the whord $key\n";
> }

TMTOWTDI :o]

 #!/usr/local/bin/perl -w

 use strict 
 open (FILE,$0) or die $!; # this reads itself
 my($data,%count); 
 { local $/ = undef;   # erases the record seperator for this block
   $data = ; # slurps in the whole file to $data
 }   
 close(FILE);  # good habit
 map { $count{$_}++ } $data =~ /(\w+)/sog; # watch the context!
 print map { "$count{$_} occurances of '$_'\n" } sort keys %count;

Perl is a wonderfully concise language.
The above is strictly given as an example of a few performance tricks
that are worth researching. =o)

Paul
 

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Re: [BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Sean O'Leary

At 11:17 AM 4/24/2001, you wrote:
>so...this is suposed to count the words in FILE and return how many 
>occourances of each word there were...its not working for me thoughits 
>only returning the count for the last word in the file...help
>
>#!/usr/local/bin/perl
>
>open (FILE,"../www/main.php3");
>@lines=;
>close(FILE);
>
>foreach $i (@lines) {
>@words = split(/\s+/, $i);
>}

The loop above clobbers @words each time.  The loops below only work on the 
last line of the file.

>foreach $word (@words) {
>$wordcount{"$word"}=0;
>}

You're initializing every entry in the hash to 0, and you don't have to do 
that.  The rest of the code looks good. But we still have to deal with the 
problem of not getting all of the words into @words.

I think this would work, if used as the first loop of the program.

foreach (@lines) {
 push @word, split /\s+/;
}

With the loop above, as you split words out of @lines, they get _added_ to 
@words.  The assignment operator, =, would clobber the value already there, 
leaving us with just the last thing we assigned to it, the last line of the 
file.  Look in perlfunc for the push, pop, shift, and unshift 
functions.  If you don't know about stacks and queues, get a decent book on 
data structures and check them out.  They are amazingly powerful for how 
simple they are, and Perl is nice enough to have all the stuff built in so 
you can treat regular arrays like either (or both) of them.

As for hashes, when you use a hash key for the first time, the value is 
undef.  Undef, in a numeric context, looks like 0.  So all we have to do is 
add 1 for each time we see a word, and we are ok.  There's no need to 
initialize them all to zero.  So your program would become something that 
looks like this.

use strict;

open FILE, "../www/main.php3" or die "Can't open the file: $!";
# I added the "or die ..." above, because you want your
# program to halt if you have no data to work on.  You
# also want to check the return values of functions that
# do stuff outside of your program, to make sure that
# the succeed.
@lines=;
close(FILE);

foreach (@lines) {
 push @words, split /\s+/;
}

my %wordcount = ();

foreach my $word (@words) {
 # Oh, my $word!  : )
 $wordcount{$word}++;
 # $var++ is shorthand for $var += 1
 # but either is fine.
}

But, this can be cleaned up further!  You can compress it all down to one 
loop, in a few different ways.  Take another look at it Chris, play with 
it, and crunch it down.  Less code, less bugs, less stuff to worry about.

Good luck!

Thank you for your time,

Sean.




Re: its not homework

2001-04-24 Thread Chris Brown

its no deal man...i got it to work...thanks a ton for the help you guys. Im
sure it wont be long until next time.
Chris Brown




Re: its not homework

2001-04-24 Thread Casey West

On Tue, Apr 24, 2001 at 10:56:53AM -0500, Chris Brown wrote:
: i have done some cgi stuff like a guestbook and a script to display random images 
:but i wanted to get deeper so i thought i would try this...im not in any classes...i 
:guess you could call it personal homework...but its not really homework...thanks
: Chris Brown

Cool, sorry for the suspicion.

-- 
Casey West



Re: [OT]Re: Admin idea

2001-04-24 Thread Paul


--- Sean O'Leary <[EMAIL PROTECTED]> wrote:
> At 09:57 AM 4/24/2001, you wrote:
> >And I almost forgot to send this to the list!
> >See? lol
> 
> See how useful that Reply-To can be?  : )
> 
> Sean.

Even more than you think -- I mistyped the address on the CC: to the
list, and it bounced back!


__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



a resend

2001-04-24 Thread Paul


--- [EMAIL PROTECTED] wrote:
> 
> 
> All,
>  I 've an output from the system comand as follows.
> 
> *   /xxx/  /yyy/
> *   /www/  /vvv/
> *  /uuu/   /ttt/
> :::
> 
>  I want to parse this output into an array and split them and
> process each entry. Essentially, I want to parse the output of a
> command to an array and process each entry in the array.
> 
> My code is
> 
> my @vob_list = system ("cleartool lsvob") ;

This isn't how system() works.
You need to either use 
 my @vob_list = `cleartool lsvob`; # works, but might get kludgy

or, more to my preference,

 open VOB, "cleartool lsvob|" or die $!; # opens a pipe

then alter this:
> foreach $entry (@vob_list) {
to this:
  while(my $entry=) {

> print " This is first '$entry'" ;
> }

The final result:


 open VOB, "cleartool lsvob|" or die $!; # opens a pipe
 while(my $entry=) {
print " This is first '$entry'" ;
 }


 
> I am a beginner, so bear with me if there are blunders.

No problem. =o)

> Thanks in advance for any help.
> Kailash

You're welcome.

Paul



__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



its not homework

2001-04-24 Thread Chris Brown

i have done some cgi stuff like a guestbook and a script to display random images but 
i wanted to get deeper so i thought i would try this...im not in any classes...i guess 
you could call it personal homework...but its not really homework...thanks
Chris Brown



Re: [BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Collin Rogowski

The problem is that you override the (global) array @words for each line.
You go through @lines and the split overrides @words!
While we are at it... ;-)

You do not need that many loops. The programm will be much simpler like
that:

open(FILE, "yourFileName");

while ($line = ) { #no need to read the file into an array
  @words = split/\s+/, $line; #just process each line as it comes
  foreach $word (@words) {
$wordcount{$word} += 1; #no need to initialize the hash with 0,
#perl does that for you
  }
}
close(FILE);

foreach $word (keys %wordcount) {
  print $word, ": ", $wordcount{$word}, "\n";
}


hope this helps,

cr

P.S.:
If you have question about the code above, feel free to ask.


On Tue, 24 Apr 2001 10:17:02 -0500, Chris Brown said:

> so...this is suposed to count the words in FILE and return how many occourances of 
>each word there were...its not working for me thoughits only returning the count 
>for the last word in the file...help
>  
>  #!/usr/local/bin/perl
>  
>  open (FILE,"../www/main.php3");
>  @lines=;
>  close(FILE);
>  
>  foreach $i (@lines) {
>  @words = split(/\s+/, $i);
>  }
>  
>  foreach $word (@words) {
>  $wordcount{"$word"}=0;
>  }
>  
>  foreach $word2 (@words) {
>  $wordcount{"$word2"}+=1;
>  }
>  
>  foreach $key (keys (%wordcount)) {
>  print "$wordcount{$key} occourances of the whord $key\n";
>  }
>  
>  




Re: [BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Casey West

On Tue, Apr 24, 2001 at 10:17:02AM -0500, Chris Brown wrote:
: so...this is suposed to count the words in FILE and return how many occourances of 
:each word there were...its not working for me thoughits only returning the count 
:for the last word in the file...help

The following is a generality, not directly related to this question (
unless it is homework ;).

Please note that I will not allow this list to do anyone's homework.
Answering homework style questions with simple 'go read xxx' is fine,
though.  Pointers are very different from doing work for a student.

-- 
Casey West



Re: [BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Timothy Kimball


: so...this is suposed to count the words in FILE and return how many occourances of 
:each word there were...its not working for me thoughits only returning the count 
:for the last word in the file...help

Think: In the first loop, what happens to the first line when you move
to the second?

(Sorry for the terse answer, but this one sounds like a homework
problem. ;)

--
Tim Kimball · ACDSD / MAST¦ 
Space Telescope Science Institute ¦ We are here on Earth to do good to others.
3700 San Martin Drive ¦ What the others are here for, I don't know.
Baltimore MD 21218 USA¦   -- W.H. Auden



Re: files, mask

2001-04-24 Thread Michael Lamertz

[EMAIL PROTECTED] 
([EMAIL PROTECTED]) wrote:
> i input as arguments a dir and a mask, and i need to get the name's of
> the files of that mask in that dir on an array, how can i do this?

Use the glob function - perldoc -f glob

-- 
 If we fail, we will lose the war.

Michael Lamertz  | [EMAIL PROTECTED] / [EMAIL PROTECTED]
Nordstr. 49  | http://www.lamertz.net
50733 Cologne| Work: +49 221 3091-121
Germany  | Priv: +49 221 445420 / +49 171 6900 310



[BPQ] help!! any idea whats wrong with this??

2001-04-24 Thread Chris Brown

so...this is suposed to count the words in FILE and return how many occourances of 
each word there were...its not working for me thoughits only returning the count 
for the last word in the file...help

#!/usr/local/bin/perl

open (FILE,"../www/main.php3");
@lines=;
close(FILE);

foreach $i (@lines) {
@words = split(/\s+/, $i);
}

foreach $word (@words) {
$wordcount{"$word"}=0;
}

foreach $word2 (@words) {
$wordcount{"$word2"}+=1;
}

foreach $key (keys (%wordcount)) {
print "$wordcount{$key} occourances of the whord $key\n";
}




Re: Parsing the output

2001-04-24 Thread Timothy Kimball


:  I 've an output from the system comand as follows.
: 
: *   /xxx/  /yyy/
: *   /www/  /vvv/
: *  /uuu/   /ttt/
: :::
: 
:  I want to parse this output into an array and split them and process each
: entry. Essentially, I want to parse the output of a command to an array and
: process each entry in the array.
: 
: My code is
: 
: my @vob_list = system ("cleartool lsvob") ;
: foreach $entry (@vob_list) {
: print " This is first '$entry'" ;
: }

You've got a good start on it so far. You just need to use backticks
instead of system(), which doesn't return the output of the command,
and split the line into fields:

my @vob_list = `cleartool lsvob`;
foreach $entry (@vob_list) {
chomp $entry;
my @fields = split /\s+/, $entry;
...
}

For the first line, $fields[0] will contain '*', $fields[1] will
contain '/xxx/', $fields[2] will contain '/yyy/', and so on.
(The "chomp" will get rid of the newlines at the end of each line.)

Another way to do it might be to open a pipe to the command and read
the output of that, instead of creating the array beforehand:

open CMD, "cleartool lsvob |" or die "Couldn't open pipe" $!";
while () {
chomp;
my @fields = split;
...
}
close CMD;

My favorite way, especially if the argument to cleartool comes from
outside, would be to open a pipe onto a child process. This one's a
little weird, but because of the way exec() works, it's more secure:

open CMD, "-|" or exec "cleartool", "lsvob";
while () {
chomp;
my @fields = split;
...
}
close CMD;

When you open "-|", Perl automatically forks a child process, which is
what the other side of the "or" will be- in this case, and exec. The
arguments to exec() are passed as a list; when you do that, exec()
won't open a shell to execute the command. So if "lsvob" comes from
outside the program, it will be handled more securely. (Hint: what
will the command do if the argument to "cleartool" is "lsvob; rm *"?)

TIMTOWTDI

--
Tim Kimball · ACDSD / MAST¦ 
Space Telescope Science Institute ¦ We are here on Earth to do good to others.
3700 San Martin Drive ¦ What the others are here for, I don't know.
Baltimore MD 21218 USA¦   -- W.H. Auden



Re: Parsing the output

2001-04-24 Thread Michael Lamertz

[EMAIL PROTECTED] ([EMAIL PROTECTED]) wrote:



> My code is
> 
> my @vob_list = system ("cleartool lsvob") ;
> foreach $entry (@vob_list) {
> print " This is first '$entry'" ;
> }

use 'perldoc perlop' and look for 'qx'.  The system call doesn't catch
the output of the called program.  For this you need either the qx
operator or backticks - also explained in the qx section of the docs.

-- 
 If we fail, we will lose the war.

Michael Lamertz  | [EMAIL PROTECTED] / [EMAIL PROTECTED]
Nordstr. 49  | http://www.lamertz.net
50733 Cologne| Work: +49 221 3091-121
Germany  | Priv: +49 221 445420 / +49 171 6900 310



RE: print statment

2001-04-24 Thread Paul


And for those with embedded JavaScript to write, in which you already
have too many quotes:  =o)

print< wrote:
> David Gilden writes ..
> 
> >Original from the class:
> >
> >print " checked>\n";
> >
> >
> >Is this bad style?
> 
> yep .. avoid backwhacks at all costs - that's my opinion
> 
> 
> >print ' checked>',"\n";
> >
> >better?
> 
> yep .. much better
> 
> >print ''.
> "\n";
> 
> also good - but generally accepted as inferior to the second snippet
> 
> >I do believe that these 3 statements are all equivalent. 
> 
> nope .. but the differences are subtle .. the first one is
> essentially
> equivalent to the last one .. but the one with the comma is different
> in
> that it passes two parameters as a list to the print function and can
> be
> affected by the built-in variable $,
> 
> to see the difference try this code snippet
> 
>   $, = '_wow_';
> 
>   print 'foo', 'bar', "\n";
> 
>   print 'foo'. 'bar'. "\n";
> 
> but - use of $, is pretty rare and usually discouraged and the second
> snippet that you showed is the best of the three
> 
> even better is to realise that double-quotes are operators ..
> specifically
> they're shorthand for the qq// operator .. in other words the
> following two
> are EXACTLY equivalent to Perl
> 
>   print "foobar\n";
>   print qq/foobar\n/;
> 
> so .. when you want to include double-quotes AND have the string
> interpolated you can do this
> 
>   print qq/ checked>\n/;
> 
> also note that the '/' character is not the only delimiter that you
> can use
> .. you can use anything .. so the following are all equivalent to the
> above
> 
>   print qq# checked>\n#;
>   print qq* checked>\n*;
>   print qq| checked>\n|;
> 
> even the rather obfuscated
> 
>   print qq q checked>\nq;
> 
> you can even use bracketing constructs and Perl will pair them up ..
> so the
> following works a treat
> 
>   print qq(some more parens () in here - perl isn't fooled\n);
> 
> 
> Manual Refereces:
> 
>   "Quote and Quote-like Operators" section of perlop manual
> 
> -- 
>   jason king
> 
>   No children may attend school with their breath smelling of "wild
>   onions" in West Virginia. - http://dumblaws.com/


__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Parsing the output

2001-04-24 Thread Kailash . Subramanian



All,
 I 've an output from the system comand as follows.

*   /xxx/  /yyy/
*   /www/  /vvv/
*  /uuu/   /ttt/
:::

 I want to parse this output into an array and split them and process each
entry. Essentially, I want to parse the output of a command to an array and
process each entry in the array.

My code is

my @vob_list = system ("cleartool lsvob") ;
foreach $entry (@vob_list) {
print " This is first '$entry'" ;
}

 I am a beginner, so bear with me if there are blunders.

Thanks in advance for any help.

Kailash





RE: Net::DNS::MX data

2001-04-24 Thread Matt Cauthorn

Don't mean to beat this horse, but I ran across an MX
script  that really worked out for us at work. Here it
is. Hope it helps someone out there. Comments welcome,
as I've got a long way to go!! I think most of it
comes from the docs, though:

#!/usr/bin/perl -w
# This one compares mx data from 2 servers
use strict;
use Net::DNS;
 Parse the file
open IN, "C:/Documents and
Settings/mcauthorn/Desktop/perl_crap/zones_final.txt"
|| die "can't open \n";

my (@lines,@domain_names);
@lines=();
chomp @lines;
close IN;
my %name_servers=(
'xxx.xxx.xxx.xxx'=>'servera',
'xxx.xx.xxx.xxxj'=>'severb'
);
my $res = new Net::DNS::Resolver;
foreach my $zone (@lines){
foreach my $server(keys %name_servers){
$res->nameservers($server); 
my $query = $res->query($zone);
sleep 1;
  if (!$query){
print "Query error for $zone! \n";
next;
}
foreach my $rr ($query->answer) {
 print "$server -->$zone : ", $rr->address ,"\n";
 my @mx=mx($res, $zone); 
if (@mx){
 foreach $rr (@mx){
 print "MX: ", $rr->preference, " ",$rr->exchange,
"\n";
}
   } else {print "No mx data for $server \n";}

  }  } print "\n";
 }#top foreach close ($zone)


# Sorry about the crappy copy / paste.

~Matt

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Re: sysread and buffering

2001-04-24 Thread Paul


Another possible solution is to use Brian Ingerson's Inline.pm and code
the reads &c. with C's lower level IO. I think a C getc() would do
it

But be warned that, while it's actually quite friendly, a raw beginner
might have some trouble with the Inline stuff, especially if they don't
know C. I'd say look, maybe try, and decide based on your own
confidence.

Good luck.

--- Sean O'Leary <[EMAIL PROTECTED]> wrote:
> At 05:25 PM 4/23/2001, Janet Lee wrote:
> >Hi all.
> >
> >I'm trying to do what I think is a very simple thing. I want to read
> >keyboard input char by char and time the difference between each
> keystroke.
> >I've tried using
> >
> >while (sysread STDIN, $key, 1) {
> > dostuff
> >};
> >
> >but that seems to be doing some kind of buffering so that the body
> of the
> >while loop is only executed after a carriage return. i'm using
> activeperl on
> >a windows machine. is it possible to do what i want to do in perl?
> is there
> >another call i should be using? TIA
> >
> >janet
> 
> 
> The reason why some of this is going on (only executing after the
> return) 
> probably has to do with input buffering and such.  I thought sysread
> was 
> supposed to bypass that (that is, read from the file, really, not the
> 
> buffer that's hanging around looking like the file, but I could be 
> wrong.)  You may be able to do some stuff to STDIN to turn all the 
> buffering off, but I think that might be more trouble than it's
> worth.  I 
> think the module that you want is:
> 
> http://search.cpan.org/search?dist=TermReadKey
> 
> You can install it with PPM, no problem.  If you need help with that,
> just 
> write back to the list saying so.
> 
> Thank you for your time,
> 
> Sean.
> 


__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



  1   2   >