[10887] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4488 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 23 16:07:51 1998

Date: Wed, 23 Dec 98 13:00:23 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 23 Dec 1998     Volume: 8 Number: 4488

Today's topics:
    Re: $ troubles <Paul.Makepeace@POBox.com>
    Re: $|=0 (M.J.T. Guy)
    Re: a nicer way? (Andre L.)
    Re: Anyone have a workaround for crippled ActiveState p (Clinton Pierce)
        Bar code gif generation lucinda.moutou@digital.com
    Re: Big-Endian to Little-Endian <tlynch@cisco.com>
        Closure and lexical scoping bug(?) in Perl <Paul.Makepeace@POBox.com>
    Re: counterintuitive behavior of "shift" (M.J.T. Guy)
        doscp command in program (Randy Snott)
    Re: Equivilent of C's is_alpha() function? <uri@ibnets.com>
    Re: Equivilent of C's is_alpha() function? (Larry Rosler)
    Re: Equivilent of C's is_alpha() function? (Mark-Jason Dominus)
    Re: Equivilent of C's is_alpha() function? <Paul.Makepeace@POBox.com>
    Re: gmtime on SGI different (Daniel E. Macks)
    Re: hashes with arrays as values? (M.J.T. Guy)
    Re: hashes with arrays as values? (M.J.T. Guy)
    Re: How do I change current working directory ? (M.J.T. Guy)
        How to put a password and user name in socket program <rhart@nih.gov>
    Re: Installing Perl on Windows 95 or Windows 98 ptimmins@netserv.unmc.edu
        link checker help <mtg82814@melsud.res.ray.com>
    Re: list of bundled modules (Clay Irving)
        need help speeding up program <dewitt@jlab.org>
    Re: Newbie- Close error - Bad File Number <jeromeo@atrieva.com>
    Re: pre-ANNOUNCE : Script for fixing postscript files. (M.J.T. Guy)
        REGex that doesn't work, why? (Jim Matzdorff)
    Re: REGex that doesn't work, why? <uri@ibnets.com>
        Regular expression optimization... <stefan@waldherr.org>
        Running Perl/tk? <ilya@napavlly.rose.hp.com>
    Re: sort it ? (M.J.T. Guy)
        Stock Quotes via CGI Scripts <webmaster@wdis.com>
    Re: Where can you get undump <rra@stanford.edu>
    Re: while (<>) and $!\n (Andrew M. Langmead)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Wed, 23 Dec 1998 20:10:54 -0000
From: "Paul Makepeace" <Paul.Makepeace@POBox.com>
Subject: Re: $ troubles
Message-Id: <75ritv$8v7$1@statler.server.colt.net>

[ Cc: mailed to author ]

bl968@my-dejanews.com wrote in message <75pepu$ad7$1@nnrp1.dejanews.com>...
>I am reading in a file which terminates with a $ to show the proper end of
>file.
>
>I am trying to read the file to verify that the $ is in the file and thus
is
>valid.
>
>The problem i get is that perl seems not to recognize the fast that the $
is
>what i am looking for.
>
>Any help is appreciated.


My random guess is your trying to match $ using the // regex operator. This
is interpreted by perl as meaning 'match this pattern at the end of the
line' rather than a literal dollar. To persuade perl not to do this sort of
interpretation you need to quote or escape it with a \ i.e. \$.
Alternatively (and it's probably worth doing this anyway, given the number
of times people accidently search for special characters) check out the \Q
pseudo-character in Perl's 'perlre' page (perldoc perlre) and you'd have
/\Q$/.

Since you're looking for it at the end of the file, look for /\$$/ -- that
second $ means the 'match this pattern at the end of the line'. (Bear in
mind in this example \Q would be a bad idea as it'd stop the second $ being
interpreted as special.)

You can use the m// operator instead. I have a penchant for the - character
if the regex I'm using has backslashes. I.e. m-\$$-

To efficiently get to the end of the line, Sam Holden's seek idea is good.
I've used -3 as the offset back into the file in case there's a final
newline and on some OSs that can be two characters.

# assuming you have FILE open and readable
seek FILE, -3, 2 or die "Couldn't seek: $!";
print "Thar be dollars at the end o' this file!\n" if <FILE> =~ m-\$$-;

The point of this post was really to highlight quoting special characters in
regexes. Other perfectly reasonable solutions might revolve around using
chomp and substr with a negative offset (perldoc -f substr).

Paul

--
Paul Makepeace, Independent Thinkers Ltd (UK)
0171 377 8668 / 0973 800436
"People are all monkeys, and I am Captain Banana"
 -- Vincent Gallo






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

Date: 23 Dec 1998 18:30:19 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: $|=0
Message-Id: <75rcrr$q3v$1@pegasus.csx.cam.ac.uk>

brian d foy <comdog@computerdog.com> wrote:
>In article <36775234.B5DACEF3@idt.net>, jamesht <jamesht@idt.net> posted:
>
>> I believe that you've got it backwards. If you print $| = 1; in the
>> beginning of your script, it automatically flushes the buffer without
>> waiting for further input.
>
>$| doesn't cause buffers to be flushed.  it tells perl to flush
>buffers after each print.  not quite the same thing (as pointed out
>earlier this week).

That used to be the case, but modern Perls (since 5.004?) do an
automatic flush when you set $|=1; .   With older Perls, you had to go

         $| = 1; print '';


Mike Guy


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

Date: Wed, 23 Dec 1998 12:48:01 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: a nicer way?
Message-Id: <alecler-2312981248010001@dialup-579.hip.cam.org>

In article <36811F02.736F8307@catnmoose.com>, Marty Landman
<marty@catnmoose.com> wrote:

> I need help improving my Perl usage.  Here's a routine I've written and
> would like to know a nicer way to do the last three assignments (and any
> other suggestions).


Here's a _very_ nice way:


   use CGI qw/:standard/;

   my $id   = param('id');
   my $name = param('name');
   my $info = param('info');


HTH,
Andre


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

Date: Wed, 23 Dec 1998 17:03:31 GMT
From: cpierce1@mail.ford.com (Clinton Pierce)
Subject: Re: Anyone have a workaround for crippled ActiveState perl -- fork()
Message-Id: <368121a6.1382791914@news.ford.com>

On Mon, 21 Dec 1998 19:04:33 GMT, hutchiss@my-dejanews.com wrote:
>Thanks, Steven!
>
>I tried the Win32::CreateProcess trick, and ran into the next wall:
>if you try to open COM1 to read in one process and to write in another
>process, one or the other process will be denied permission.  I'm still
>trying to find the Win98/NT equivalent magic to let me past this.
>Amazing things show up in searches for 'share devices serial port Windows'
>but very few of them contain more than one keyword and so far none have
>been useful.

The Joy of Win32 programming.  I did something like this, and actually
wound up with a dedicated process (?Process?) just to do device I/O and
other processes to talk to it via sockets[1].  Bleh.  Expensive, kludgy,
but it worked.


[1] I want my SYSV IPC!

-- 
 Clinton A. Pierce    "If you rush a Miracle Man, you get rotten
 cpierce1@ford.com        miracles" --Miracle Max, The Princess Bride
fubar@ameritech.net   http://www.dcicorp.com/~clintp


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

Date: Wed, 23 Dec 1998 20:13:56 GMT
From: lucinda.moutou@digital.com
Subject: Bar code gif generation
Message-Id: <75riu2$27o$1@nnrp1.dejanews.com>

Hi,

I need to generate barcode GIFs (or jpegs).  The perl module for this
purpose generates postscript.  Also, there is a postscript/TT font available
that does barcodes.  Finally, there must be someone who's done this before.

>From this one need and three pieces, can anybody suggest how to connect point
A to point B? (ie convert ps to gif, print fonts as gifs, or other solution)

Thanks,
Lucinda

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 23 Dec 1998 13:15:31 -0500
From: Tom Lynch <tlynch@cisco.com>
Subject: Re: Big-Endian to Little-Endian
Message-Id: <36813343.67E5BFA9@cisco.com>

Hi:
	
	Thanks! That's very cool. I was looking under Math::
	must have missed that one.

	Thanks Again
	  Tom

Steffen Beyer wrote:
> 
> The module Bit::Vector has a built-in method for reversing bit-order...
> 
> And the module is internally written in C...
> 
-- 
#-----------------------+--------------------------+
# Tom Lynch             | Email: tlynch@cisco.com  |
# Cisco Systems         | Phone: 978-244-8765      | 
# 250 Apollo Drive      | FAX:   978-244-8039      |
# Chelmsford MA 01824   | MS:    CH1-2LF           |
#-----------------------+--------------------------+


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

Date: Wed, 23 Dec 1998 20:19:28 -0000
From: "Paul Makepeace" <Paul.Makepeace@POBox.com>
Subject: Closure and lexical scoping bug(?) in Perl
Message-Id: <75rje3$93m$1@statler.server.colt.net>

I posted this on London.pm (wahey!) and after a little discussion the
consensus was that it was a bug. It hasn't elicited a response from perlbug
yet. I'm posting it here for general interest and to see how many people
actually use closures...

If anyone can explain the behaviour of the following, please let me know.

#!/usr/bin/perl -w
use strict;

{
        my $base = "Hello, ";
        sub msg {
                #print "Making a message starting with '$base'...\n";
                #$base=$base;
                my $what = shift ;
                sub {
                        print "$base$what\n"
                }
        }
}

my $greeting = msg("world");
&$greeting;

:!perl funcbug.pl
Use of uninitialized value at funcbug.pl line 10.
world

If the first debug print or $base=$base line is uncommented or the outer
braces removed, it works producing the expected "Hello, world". This happens
on both 5.004_04 and 5.005_02.

Paul.

--
Paul Makepeace, Independent Thinkers Ltd (UK)
0171 377 8668 / 0973 800436
"People are all monkeys, and I am Captain Banana"
-- Vincent Gallo








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

Date: 23 Dec 1998 19:33:49 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: counterintuitive behavior of "shift"
Message-Id: <75rgit$t1d$1@pegasus.csx.cam.ac.uk>

In article <759o7n$2f5@disco.cs.columbia.edu>,
Dragomir R. Radev <radev@news.cs.columbia.edu> wrote:
>----------------------------------------------------------------------------
>bla.pl:
>
>#!/bin/perl
>
>$par1 = shift || 1;
>$par2 = shift || 2;
>
>print "$par1 $par2\n";
>----------------------------------------------------------------------------
>
>% bla.pl 5 6
>% 5 6
>% bla.pl 0 6
>% 1 6             instead of "0 6"
>
>I find this logical from Perl's point of view, yet very
>counterintuitive and confusing.

Other responses have indicated how to fix this up using defined(),
but I consider it better practice not to do shift() on an empty array in
such cases.  Instead you can do something like

     $par1 = @ARGV ? shift : 1;


Mike Guy


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

Date: Wed, 23 Dec 1998 18:44:19 GMT
From: Vommyt1@mapSoN.primenet.com  (Randy Snott)
Subject: doscp command in program
Message-Id: <368139fb.7928986@news.jet.net>

I am attempting to get a program to pull a file from a directory and
copy it onto a floppy drive. I have a dos formatted disk in the drive
and can run "doscp filename a:"  in the shell. When I attempt to do
the same from inside my program. I get 
Usage: doscp [-r | -m] device:path  . . .  device:path  
sh: a:: not found 

I have tried using backticks, system(), exec() and even calling out
the full name of the device, all with the same result. I am using Perl
5.005_02 on a SCO Unix 5.04 server.


Any ideas?

Thanks for any help, and a very informational group,

Jeff Griffith
Jeff@avantasoft.com


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

Date: 23 Dec 1998 13:25:06 -0500
From: Uri Guttman <uri@ibnets.com>
Subject: Re: Equivilent of C's is_alpha() function?
Message-Id: <39vhj23ed9.fsf@ibnets.com>

>>>>> "a" == aaron1  <aaron1@citizen.infi.net> writes:

  a> I'm trying to parse a file, and I need to determine if the string variable
  a> that I have the line in contains alphanumeric data or numeric data.  So I'm
  a> wondering if Perl has a function like C's is_alpha()?

why should it? perl has regexes which can do all of the is_* functions
and more. see perlre or go to www.perl.com and rtfm.

you say you are parsing a file and i assume in perl, so why not learn
how to use perl to parse things?

hth,

uri

-- 
Uri Guttman                             Hacking Perl for Ironbridge Networks
uri@sysarch.com				uri@ironbridgenetworks.com	


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

Date: Wed, 23 Dec 1998 10:51:54 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Equivilent of C's is_alpha() function?
Message-Id: <MPG.10eadba559ae42eb9898f1@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and a copy mailed.]

In article <75r8ia$p91$1@nnrp1.dejanews.com> on Wed, 23 Dec 1998 
17:17:02 GMT, aaron1@citizen.infi.net <aaron1@citizen.infi.net> says...
> I'm trying to parse a file, and I need to determine if the string variable
> that I have the line in contains alphanumeric data or numeric data.  So I'm
> wondering if Perl has a function like C's is_alpha()?

Your terminology is rather vague.  The C function to identify an 
alphanumeric character (letter, digit or underscore) is isalnum().  The 
function to identify an alphabetic character (letter) is isalpha().  I 
assume you mean the latter.

You can use a character class in a regex.

/[^\W\d_]/

matches a single character that is alphabetic (alphanumeric, but not a 
digit and not an underscore).  The definition of alphabetic is locale-
dependent (see `perldoc perllocale`); by default it is /[A-Za-z]/.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 23 Dec 1998 14:26:54 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Equivilent of C's is_alpha() function?
Message-Id: <75rg5u$l4k$1@monet.op.net>

In article <75r8ia$p91$1@nnrp1.dejanews.com>,  <aaron1@citizen.infi.net> wrote:
>I'm trying to parse a file, and I need to determine if the string variable
>that I have the line in contains alphanumeric data or numeric data.  So I'm
>wondering if Perl has a function like C's is_alpha()?

You can check all the characters in the string at once by doing:

	if ($string !~ /[\W\d_]/) {
	  # It contains letters only.
	}

This will work in French, German, and other languages if the locale is
set properly.

If you don't care about languages other than English, you can use

	if ($string !~ tr/A-Za-z//c) { ... }

instead, which will probably be more efficient.



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

Date: Wed, 23 Dec 1998 19:41:50 -0000
From: "Paul Makepeace" <Paul.Makepeace@POBox.com>
Subject: Re: Equivilent of C's is_alpha() function?
Message-Id: <75rh7g$8fj$1@statler.server.colt.net>


Larry Rosler wrote...
>In article <75r8ia$p91$1@nnrp1.dejanews.com> on Wed, 23 Dec 1998
>17:17:02 GMT, aaron1@citizen.infi.net <aaron1@citizen.infi.net> says...
>> I'm trying to parse a file, and I need to determine if the string
variable
>> that I have the line in contains alphanumeric data or numeric data.  So
I'm
>> wondering if Perl has a function like C's is_alpha()?
>
>[snip: <ctype.h> clarification]
>
>You can use a character class in a regex.
>
>/[^\W\d_]/

(Indeed)

/[[:alpha:]]/ would be the POSIX way. A variety of GNU tools have
implemented this but not perl.

>digit and not an underscore).  The definition of alphabetic is locale-
>dependent (see `perldoc perllocale`); by default it is /[A-Za-z]/.

Strictly, the definition of alphabetic is [0-9a-zA-Z_] i.e. \w : it's only
locale dependent if you tell Perl so (with the 'use locale;' pragma). By
default Perl ignores locale. (AIUI)

use POSIX qw(isalpha);

my $found_alpha;
for (split //) {
    $found_alpha = isalpha($_) and last;
}

;-)

Paul




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

Date: 23 Dec 1998 18:24:06 GMT
From: dmacks@mail2.sas.upenn.edu (Daniel E. Macks)
Subject: Re: gmtime on SGI different
Message-Id: <75rcg6$5pl$1@netnews.upenn.edu>

mbrennan@observera.com said:
[POSIX gmtime returns different strings running under IRIX 6.3 and
perl 5.002 vs. 6.5/5.004_04]
: 
: I don't know if this is a result of the OS upgrade or Perl upgrade. My guess
: is it's due to the OS upgrade, but I want to get a second opinion so I know
: what my code should check for (when I add an 'if statement' around the date
: format code).

IIRC, the string formats are defined in /usr/lib/local/$LANG/LC_TIME/
(or some moral equivalent). One positive aspect is that it's easy to
set up a French system that formats the date with French month and day
names, etc. One drawback is that the exact format of any function that
formats date strings can change. For your situation, consider (as
someone else posted) doing all the string formatting yourself.

dan
--
Daniel Macks
dmacks@a.chem.upenn.edu
dmacks@netspace.org
http://www.netspace.org/~dmacks



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

Date: 23 Dec 1998 18:50:36 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: hashes with arrays as values?
Message-Id: <75re1s$qus$1@pegasus.csx.cam.ac.uk>

Bart Lateur <bart.lateur@skynet.be> wrote:
>	@{$hash{mango}} = (9,8,7,6,5,4,3,2,1,0);
>
>For some reason, you may NOT drop the outer braces in this case. I don't
>feel like searching on the why, as I personally would find it less
>readable. Yes, I actually LIKE the @{...} or %{...} syntax. :-)

Operator precedence.   Without the (), that would be the same as

       ( @{$hash{mango}} = 9 ),8,7,6,5,4,3,2,1,0;


Mike Guy


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

Date: 23 Dec 1998 18:55:51 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: hashes with arrays as values?
Message-Id: <75rebn$ram$1@pegasus.csx.cam.ac.uk>

Andrew M. Langmead <aml@world.std.com> wrote:
>        The line
>
>>    @hash{mango} = (9,8,7,6,5,4,3,2,1,0);
>
>replaces the array reference held in $hash{mango} with the value
>0.

You obviously haven't tried it.   That's a list assignment, not a scalar
assignment, so it assigns 9, not 0.


Mike Guy


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

Date: 23 Dec 1998 18:35:55 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: How do I change current working directory ?
Message-Id: <75rd6b$qfj$1@pegasus.csx.cam.ac.uk>

Adam Stoller <ghoti@telerama.lm.com> wrote:
>
>Peter Forsbom wrote in message <36779D06.A00A286F@statoil.com>...
>>I want to change the current working directory so when my perl program
>>is done my pwd is diffrent from when I started the program.
>>
>>Peter Forsbom
>
>In general, a process (your script) spawned by another process (your shell),
>cannot alter the spawning process (your shell).
>
>The general alternative is to have your script itself spawn a new shell -
>and thus your script won't end until that shell is killed.
>
>#!/bin/perl
>[do some stuff - set environments, etc.]
>chdir("/some/path");
>exec($SHELL);
>exit 0;

That "exit 0;" is a rather eccentric thing to do.   exec() will only
return if it fails, so it'd be better to follow it with something like

   die "Couldn't exec $SHELL: $!\n";


Mike Guy


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

Date: Wed, 23 Dec 1998 14:11:44 -0500
From: Robin Hart <rhart@nih.gov>
Subject: How to put a password and user name in socket program
Message-Id: <36814070.D52D2D2F@nih.gov>

 Hi All:

I have a perl program which is used to  open socket for  accessing a web
server because I need to download files
from this web server.  The file directory is protected by the web
server, but I have a password and uid to access
information from the webpage.  I don't want to download the data from
the url webpage because I need to download them one page at time.  It is
time consume for me.   Therefore, I need to write the perl script which
will
download all files at once.

I have the IP address and port number of the web site.  My question is
how to login onto the web server by an uid and a password in my perl
script.  I have no problem to open socket on that site.  Every time I
run the script, and I got this message as following:

               Authorization Required
              This server could not verify that you  are authorized to
access the document you requested.

Now, I have an user name and a password, but I don't know how to put
together with socket codes.
Anyone has an idea?

Thanks In Advance!

Happy Holidays!

Robin



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

Date: Wed, 23 Dec 1998 20:17:16 GMT
From: ptimmins@netserv.unmc.edu
To: fguarner@ix.netcom.com
Subject: Re: Installing Perl on Windows 95 or Windows 98
Message-Id: <75rj4b$2bs$1@nnrp1.dejanews.com>

** emailed and posted to clpm **
In article <75n7s6$p8@sjx-ixn10.ix.netcom.com>,
  "fguarner" <fguarner@ix.netcom.com> wrote:

> I am fascinated with learning perl, but I don't have a clue how get an
> compatible version. I've read some discouraging stuff about installing perl
> on Windows 95. Is there a version out there somewhere thats semi easy to
> install and works.
>
> Please email me at fguarner@ix.netcom.com

Another good reason to subscribe to 'The Perl Journal' ... in the latest
edition: "Installing Perl and Perl/Tk on Win32" by Steve Lidie

Patrick Timmins
$monger{Omaha}[0]

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 23 Dec 1998 14:40:00 -0500
From: Mike Godfrey <mtg82814@melsud.res.ray.com>
Subject: link checker help
Message-Id: <3681470F.C67BDFC0@melsud.res.ray.com>

Hi,
    I would like to use perl to check if an internet site exists or not,
for a link checker.  I really don't have any idea of how to do it.
I believe I need to use sockets to accomplish this, but I can't seem to
find any documentation on sockets that I can understand.  All the
documentation is so confusing, does anyone know of any sites that
explain it from the beginning?

Also, when doing the site checking I would like to check links within my
web site and links outside of it.  But to get outside I go through a
proxy, and that makes it a little more confusing.

Any help would be great.

Mike



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

Date: 23 Dec 1998 14:12:06 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: list of bundled modules
Message-Id: <75rfa6$jup@panix.com>

In <368112F9.D0936D9F@email.sps.mot.com> Tk Soh <r28629@email.sps.mot.com> writes:

>Does the perl installation come with a filelist (spececially the
>standard library) somewhere? I was hoping it should be part of
>perldoc's. I need to decide if I should advice my client on the minimum
>requirement (versions) as I used some of the 'standard' pm came
>installed with my v5.005_1, or if I should simply grab the pm's and sent
>them together with my scripts.

Like the MANIFEST file:

   # more MANIFEST
   Artistic                The "Artistic License"
   Changes                 Differences from previous version
   Changes5.000            Differences between 4.x and 5.000
   Changes5.001            Differences between 5.000 and 5.001
   Changes5.002            Differences between 5.001 and 5.002
   Changes5.003            Differences between 5.002 and 5.003
   Changes5.004            Differences between 5.003 and 5.004
   Configure               Portability tool
   Copying                 The GNU General Public License
   EXTERN.h                Included before foreign .h files
   INSTALL                 Detailed installation instructions
   INTERN.h
[...]

-- 
Clay Irving
clay@panix.com


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

Date: Wed, 23 Dec 1998 14:27:25 -0500
From: Shane Dewitt <dewitt@jlab.org>
Subject: need help speeding up program
Message-Id: <3681441D.5152@jlab.org>

hi, im new to perl and i have this program that reads a data file
containing a table of data that need to be manipulated to a different
format (more computer freindly).

the program currently take 54 seconds to parse and and write its output
to file. its seems to me that this is entirely to long.

sample input file
-----------------
###	Name		HIHI	HIGH	LOW	LOLO	HHSV		HSV		LSV	LLSV
0	IGL1I00AI17	1.321	1.521	0.721	0.921	NO_ALARM	NO_ALARM	MAJOR	MAJOR
1	MWF1I04_alarm	462.4	462.3	462.1	462	MAJOR		MINOR		MINOR	MAJOR
cut
-----------------
there are 239 rows in my data file

sample output file
------------------
--- Start BURT header
Time:     Wed Dec 23 13:17:03 EST 1998
Login ID: dewitt (Shane Dewitt)
Eff  UID: 3218
Group ID: 106
Keywords: 
Comments: 
Type:     Absolute
Directory /usr/user1/dewitt/projects/p6
Req File: 
--- End BURT header
IGL1I00AI17.HIHI 1 1.321
IGL1I00AI17.HIGH 1 1.521
IGL1I00AI17.LOW 1 0.721
IGL1I00AI17.LOLO 1 0.921
IGL1I00AI17.HHSV 1 NO_ALARM
IGL1I00AI17.HSV 1 NO_ALARM
IGL1I00AI17.LSV 1 MAJOR
IGL1I00AI17.LLSV 1 MAJOR
MWF1I04_alarm.HIHI 1 1.321
MWF1I04_alarm.HIGH 1 1.521
MWF1I04_alarm.LOW 1 0.721
MWF1I04_alarm.LOLO 1 0.921
MWF1I04_alarm.HHSV 1 NO_ALARM
MWF1I04_alarm.HSV 1 NO_ALARM
MWF1I04_alarm.LSV 1 MAJOR
MWF1I04_alarm.LLSV 1 MAJOR
cut
--------------------------
basically to get output data file just grap a "Name" append a dot and a
column heading starting a 3. next alway print a '1' then the value of
that cell.

the script file
----------------
#!/usr/local/bin/perl

# perl script to convert a user readable table of Alarms and values
# to a BURT snap file. Written for Peter Hartman by S. Dewitt.

# Usage: table2snap -f infile -o outfile

#uncomment to debug
#$DD = 1;

if(! @ARGV) {
    &Usage;
    exit(1);
}

while($_ = $ARGV[0] ) {
    shift;
    last if /^--$/; # -- no more commandline options
    if(/^-f/i) { $infile = $ARGV[0]; print "infile = $infile\n" if $DD;}
    if(/^-o/i) { $outfile = $ARGV[0]; print "outfile = $outfile\n" if
$DD;}
}

if($infile && $outfile) {
    $date = `/bin/date`; chomp($date);
    ($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) =
getpwuid($>);
    $eid  = $<;
    $dir = `/bin/pwd`; chomp($dir);
    
    open(IN, "./${infile}");
    
    # if output file size > 0 back it up
    if( -s "./${outfile}" > 0) {
	`/bin/mv $outfile ${outfile}.bak`;
    }
    open(OUT,">./${outfile}");
    $old = select(OUT);
    
    &printBurtHeader;
    
    while($line = <IN>) {
	@temp = split (/\s+/,$line);
	if($line =~ /\#/) {
	    # header found
	    foreach $item (@temp) {
		if($item =~ /\#/) {
		    ;
	    }
		elsif($item =~ /Name/i) {
		    ;
		}
		else {
		    # store suffixes into array
		    @suffix = (@suffix, $item);
		}
	    }
	    print "suffix = @suffix\n" if $DD;
	}
	elsif ($line =~ /^\d+/) {
	    # signal line
	    $pos = 1;
	    foreach $item (@temp) {
		if($item =~ /^\d+/ && $pos == 1) {
		    # digit(s) at beginning of current line only
		    # ignore numbered columns
		    print "pos = $pos\n" if $DD;
		    $pos++;
		}
		elsif($item =~ /\w+/ && $pos == 2) {
		    print "pos = $pos\n" if $DD;
		    $sigName = $item;
		    print "sigName = $sigName\n" if $DD;
		    $pos++;
		}
		else {
		    print "pos = $pos\n" if $DD;
		    $pos++;
		    @values = (@values, $item);
		    print "values = @values\n" if $DD;
		}
	    }
	    # reset sigNames array
	    @sigNames = ();
	    # build signal names
	    foreach $item (@suffix) {
		@sigNames = (@sigNames,"${sigName}.${item}");
		print "sigNames = @sigNames\n" if $DD;
	    }
	    # print signal names and values
	    $count = 0;
	    foreach $sig (@sigNames) {
		print "$sig 1 $values[${count}]\n";
		$count++;
	    }
	}
	elsif ($line =~ /^\s*/) {
	    # empty line
	    ;
	}
	else {
	    print "Error. Improperly formated file.\n";
	}
    }
}
else {
    &Usage;
    exit(1);
}
	   
sub printBurtHeader {
    print<<HEADER
--- Start BURT header
Time:     $date
Login ID: $name ($gcos)
Eff  UID: $<
Group ID: $gid
Keywords: 
Comments: 
Type:     Absolute
Directory $dir
Req File: 
--- End BURT header
HEADER
}

sub Usage {
    print<<USAGE
Usage: $0 -f infile -o outfile
where infile is a tab deliminated table and outfile is the name
of the snap file to be created if outfile already exists, it will
be backed-up.
USAGE
}


any help would greatly be appreciated. please cc any replys to:
dewitt@cebaf.gov or
								dewitt@jlab.org


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

Date: Wed, 23 Dec 1998 10:36:29 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
Subject: Re: Newbie- Close error - Bad File Number
Message-Id: <3681382D.C8DAE8E4@atrieva.com>

Tad McClellan wrote:
> 
> Jerome O'Neil (jeromeo@atrieva.com) wrote:
> : jimrsmith@unn.unisys.com wrote:
> : >
> : > I open the output file.
> : > I set autoflush to true.
> : > I select the output file.
> : > I print to the output file.
> : > (loop runs 4 times, 4 records should be written)
> : > I close the file, and STDERR gets Close error...Bad File Number
> : > output file has size 0 bytes.
> : > permissions look good.
> : > Any suggestions ?
> : > Thanks,
> : > JimBob
> 
> : Clearly you have a syntax error on line 17.
> 
>    Although the line reported is the line where the error
>    *was noticed*.
> 
>    The actual error may be on some line before the one cited.

Normaly.  I, however, ran this using Debug::Psychic with verbose
flags...

-- 
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947 
The Atrieva Service: Safe and Easy Online Backup  http://www.atrieva.com


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

Date: 23 Dec 1998 19:03:14 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: pre-ANNOUNCE : Script for fixing postscript files.
Message-Id: <75repi$rlm$1@pegasus.csx.cam.ac.uk>

Etienne Grossmann  <etienne@anonimo.isr.ist.utl.pt> wrote:
>  I had a problem today with binary data in poscscript files. I ftp'd
>files from a ms pc, and all two-character newlines were changed into
>one-character newlines. This changed the number of characters of the
>file. Some programs (ghostview, gv, gs) managed to read the files
>normally, but dvips did not : it expects some paragraphs to have a
>given length (in characters), which is specified at the beginning of
>the paragraph; upon finding that the paragraph has another length,
>dvips croaks. 

Doesn't binmode() solve the problem much more easily?


Mike Guy


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

Date: 23 Dec 1998 12:03:06 -0800
From: syran@shell1.ncal.verio.com (Jim Matzdorff)
Subject: REGex that doesn't work, why?
Message-Id: <75ri9q$o4a$1@shell1.ncal.verio.com>

I can't figure out why this doesn't return a pattern match (or I should say a "true")...

$match = "is '^]'."
$looking_for =  "/is.\'\^\]\'\.|to.console./";

if ( $match =~ $looking_for )
{
   print "yes"
}

but if you set:
$looking_for = " /\'\^\]\'|console"

it finds it just fine.

What am i missing?

--jim


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

Date: 23 Dec 1998 15:19:31 -0500
From: Uri Guttman <uri@ibnets.com>
Subject: Re: REGex that doesn't work, why?
Message-Id: <39soe6392k.fsf@ibnets.com>

>>>>> "JM" == Jim Matzdorff <syran@shell1.ncal.verio.com> writes:

  JM> I can't figure out why this doesn't return a pattern match (or I
  JM> should say a "true")...

  JM> $match = "is '^]'."
  JM> $looking_for =  "/is.\'\^\]\'\.|to.console./";

the // are part of the syntax of the m// op, not part of the regex
itself.


  JM> if ( $match =~ $looking_for )

that is better as $match =~ /$looking_for/ without the // in $looking_for.

  JM> {
  JM>    print "yes"
  JM> }

  JM> but if you set:
  JM> $looking_for = " /\'\^\]\'|console"

you don't have the // here and so it works. but the above pattern has
unneeded \ too.

you don't need to \ a ' in a "" string. nor ^ and ] in any string. they
are only special in a regex itself. the \ is being eaten by the "" so
the regex would never see them


also by choosing a better quote char you get better looking code. since
you don't interpolate in your strings, don't use a "" style. but you
want ' in your strings so i use a q{} style of quote.

so it should look more like:

	$match = q{is '^]'.} ;

	$looking_for = q{is.'^]'\.|to.console.} ;

	if ( $match =~ /$looking_for/ )


also it is not clear whether you want a literal . or the regex . (match
any char), so i didn't change the \ on .

  JM> What am i missing?

a good reading of perlre and mastering regular expressions would help a
lot.

hth,

uri

-- 
Uri Guttman                             Hacking Perl for Ironbridge Networks
uri@sysarch.com				uri@ironbridgenetworks.com	


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

Date: 23 Dec 1998 19:12:28 +0100
From: Stefan Waldherr <stefan@waldherr.org>
Subject: Regular expression optimization...
Message-Id: <upk7lviralv.fsf@amadeus.waldherr.org>

Hi,

I have a problem with a huge file that contains (line per line) regular
expressions. Thing is, that many of the regexps may be redundant and hence
matching is pretty slow. 

Is there any chance to optimize the list of regexps automatically? I would
also like to merge my regexp file with other files on the web and it would be
nice to do this automatically.

The file I'm talking about can be viewed here 

	http://www.waldherr.org/blocklist

and is intended to match annoying advertisements on web servers.

Any hints appreciated,
Stefan.
-- 
Stefan Waldherr                   fax +49 431 8058 136
                               e-Mail stefan@waldherr.org
                                  www http://www.waldherr.org/


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

Date: 23 Dec 1998 20:22:10 GMT
From: Ilya <ilya@napavlly.rose.hp.com>
Subject: Running Perl/tk?
Message-Id: <75rjdi$avn$1@ocean.cup.hp.com>




If I create a TK interface for a Perl program, and give it to someone else
to run it on their machine, does that machine have to have TK installed?
Or can I compile it into a binary like C that does not need an interpreter?

Please post your replies, thank you.


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

Date: 23 Dec 1998 19:12:59 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: sort it ?
Message-Id: <75rfbr$rs9$1@pegasus.csx.cam.ac.uk>

Micha3 Rutka <rutka@lucent.com> wrote:
>You can speed up even more if you use the original technique (without a
>name yet) rather than 'strigify' version of it:
>
>@vendors = map{ substr($_,4) } 
>           sort 
>           map{ pack("f",(split " ",$_)[$field]).$_ } @vendors;
>
>No asumption about vendors is required anymore :-).

But you're making a horrific assumption about the native floating point
format.     Highly non-portable.


Mike Guy


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

Date: Wed, 23 Dec 1998 19:19:14 GMT
From: S Sharma <webmaster@wdis.com>
Subject: Stock Quotes via CGI Scripts
Message-Id: <36816C4B.28F73839@wdis.com>

Hi,

I am trying to set up a web page which displays a particular stock quote
when that page is downloaded from the net.  It is easy enough to link to
somebody elses CGI-script and display their information in their format
on my page, but I would like to only display the current value of the
stock along with the amount it is up or down.  (similar to the way intel
does it at:
http://www.intel.com/intel/finance/index.htm?iid={intelhome=IR} )

Does anybody know how I could go about doing this using Perl?  Is there
a service out there that provides quotes to all those quote sites out
there?

Thanks any help would be appreciated as I'm stumped.




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

Date: 23 Dec 1998 10:20:11 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Where can you get undump
Message-Id: <ylzp8epvok.fsf@windlord.stanford.edu>

Abigail <abigail@fnx.com> writes:
> Gary W. Propp (gary.w.propp@cdc.com) wrote:

>> I would like to improve the performance of some perl programs. I
>> understand that the dump function produces a image core dump. The
>> documentation I have indicates you need a program undump that is not
>> part of the Perl distribution. Where can you get undump?

> In the TeX distribution.

TeX doesn't use undump any more.  The only version of it that I've seen on
CTAN was very old and only for SunOS.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Wed, 23 Dec 1998 20:51:38 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: while (<>) and $!\n
Message-Id: <F4FrA2.ADK@world.std.com>

jwl@worldmusic.de (Joergen W. Lang) writes:

>As far as I know the standard behaviour of while (<>) is 

>    open F, "test" or die "Can't open test: $!\n";
>    # Newline at the end, gives
>    # Can't open test: No such file or directory

Except that it does a warn() instead of a die(). The filehandle isn't
opened, so when read in <> it returns end of file, so it loops around
to the next file.

>Is there any way of changing this to

>    open F, test or die "Can't open test: $!";
>    # No newline, gives
>    # Can't open test: No such file or directory.
>    File 'open_test.pl'; Line 2

>so I can catch the script name and line number ? Is there any standard
>way I am missing ? I couldn'd find anything in neither Camel, Llama,

One way would be to perform the steps explicitly instead of relying on
the magic of the null filehandle. 


for $file (@ARGV) {
  open FILE, $file or warn "Can't open $file: $!";
  while(<FILE>) {
    #....
  }
}

Unfortunately, since the message from the implict open is not a "real"
warn(), it can't be trapped with a $SIG{__WARN__} handler. (Should
this be considered a bug? I'm not sure. With the arguments in
perl5porters about $SIG{__DIE__}, I'm not sure I want to ask
either. The perlop man page doesn't mention that it actually does
warn() in its explaination on <>, but it doesn't discuss the
diagnostic that is emitted.)
-- 
Andrew Langmead


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 4488
**************************************

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