[17593] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5013 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 1 21:05:32 2000

Date: Fri, 1 Dec 2000 18:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <975722708-v9-i5013@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 1 Dec 2000     Volume: 9 Number: 5013

Today's topics:
        array of unique random numbers <dela@nospam.ukonline.co.uk>
    Re: array of unique random numbers <joe+usenet@sunstarsys.com>
    Re: Can this script be done in a one-liner <elijah@workspot.net>
    Re: chdir with CGI question (David Efflandt)
    Re: Counting bits. (Craig Berry)
        DBI question <pdmos23@geocities.com>
    Re: DBI question <joe+usenet@sunstarsys.com>
    Re: Definition of solid block symbol nobull@mail.com
        Getting a File From A Different Server... acroapl@my-deja.com
        Help Me, Please <dfryberg@kent.edu>
    Re: Help Me, Please (David Efflandt)
    Re: Help Me, Please (Tad McClellan)
    Re: how do i escape from perldoc <joe+usenet@sunstarsys.com>
    Re: howto specify command line options (Greg Bacon)
    Re: Improve code with RegEx <uri@sysarch.com>
    Re: Improve code with RegEx <ren.maddox@tivoli.com>
    Re: Is there a function like LaTeX's \input ? <skuo@mtwhitney.nsc.com>
    Re: Pattern matching, I need a quick check. <joe+usenet@sunstarsys.com>
        Perl FORMAT into variable? ryanwol2000@my-deja.com
        Perl FORMAT Into variable? ryanwol2000@my-deja.com
    Re: RE:Automation rrknight@usgs.gov
    Re: Reading file into array. nobull@mail.com
    Re: regex not matching <wyzelli@yahoo.com>
    Re: strings with a minus (Tad McClellan)
    Re: strings with a minus <ren.maddox@tivoli.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 01 Dec 2000 23:54:17 +0000
From: "Dela Lovecraft" <dela@nospam.ukonline.co.uk>
Subject: array of unique random numbers
Message-Id: <3UWV5.5092$0z.83030@news2-win.server.ntlworld.com>

Dear All,

I need to produce an array of random numbers, but each of them needs
to be unique ie. if I have an array of 50 values, none can be replicated.

As far as I can see, the way to do this would be:
* set an array of n members
* put a random number in slot 1
* create another random number, and check to see that it doesn't appear
   in any of the preceeding elements - if it does, create a different number
   until it does
* repeat the above set until all n are filled.


Is this the only way to do it? If someone has a better idea, could you give
perl pointers to show how it would be done?

Thanks for your help


Dela Lovecraft




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

Date: 01 Dec 2000 19:14:47 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: array of unique random numbers
Message-Id: <m3hf4nsmq0.fsf@mumonkan.sunstarsys.com>

"Dela Lovecraft" <dela@nospam.ukonline.co.uk> writes:

> Dear All,
> 
> I need to produce an array of random numbers, but each of them needs
> to be unique ie. if I have an array of 50 values, none can be replicated.
> 
> As far as I can see, the way to do this would be:
> * set an array of n members
> * put a random number in slot 1
> * create another random number, and check to see that it doesn't appear
>    in any of the preceeding elements - if it does, create a different number
>    until it does
> * repeat the above set until all n are filled.
> 
> 
> Is this the only way to do it? If someone has a better idea, could you give
> perl pointers to show how it would be done?

% perldoc -q shuffle

Create your array of unique elements (originally in some order first), 
and then mix them up:

my @values = (0..49);
shuffle(@values);

HTH
-- 
Joe Schaefer


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

Date: 2 Dec 2000 01:37:52 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: Can this script be done in a one-liner
Message-Id: <eli$0012011934@qz.little-neck.ny.us>

In comp.lang.perl.misc, Jeff Pinyan  <japhy@pobox.com> wrote:
> >All it does is read in two lists of integers from the files a.txt and
> >b.txt, and prints out the sum of each pair.
> 
>   perl -lne 'BEGIN { @A=<>, @ARGV="b.txt" } print shift(@A)+$_' a.txt
> 
> That reads the file a.txt into the array @A, then uses b.txt for the
> implicit while (<>) { ... } loop around the program.

I've got a tool I call 'adder' that would do that like this:

	adder --noinfo --merge-files a.txt b.txt

And it nicely handles more than two files. I'll upload it to the
CPAN scripts section if there is interest.

Output of 'adder --help':
adder usage:
  adder [options] <file 

Options:
  -. --dot            print a total and reset upon input of a '.' on a line
  -1 --one            use first number on each line only (default)
  -a --all            use all numbers on each line
  -l --line           work on a per-line basis, --all becomes default range
  -f --float          allow floats (numbers with decimals)
  -n --noinfo         surpress informational text (better for parsing output)
  -m --merge-files    adds corresponding lines in multiple files
  -d --delim  RE      use RE to split each line
  -D --outputdelim  DELIM
                      use DELIM string to delimit output (default tab)
  -/ --irs    RECSEP  use RECSEP as the input record seperator (default \n)
  -\ --ors    RECSEP  use RECSEP as the output record seperator (default \n)
  -b --label  N       use column N as a label for the data (sums per label)
  -r --range  RANGE   add only numbers specified by the range (see below)
  -w --warn           turn on warnings
  -Z --debug          turn on debug output

If a delimiter is not specified with -d or --delim, the line is split
using the following method: if range is set, split on whitespace,
otherwise grab all number stretches from the line.

The format of a range is similar to that used by cut(1) or in newsrc
files. "2,3" indicates columns two and three, "4-7" indicates columns
four through seven, and "2,3,4-7" would be columns two through seven.
Column numbers start at zero (0) and open-ended ranges are not allowed.


Elijah
------
probably need a new script category for this


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

Date: Sat, 2 Dec 2000 00:54:38 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: chdir with CGI question
Message-Id: <slrn92gi25.gng.efflandt@efflandt.xnet.com>

On Fri, 01 Dec 2000 14:47:28 -0400, Gil Vautour <vautourNO@SPAMunb.ca> wrote:
>
>I have a Perl CGI script that is run from the Secure side (SSL) of my
>server.  Within the script I'm trying to chdir and output a file to my
>home directory on the same server.  The problem is that I get the "No
>such file or directory error".  The path is correct so I'm assuming it
>is because the script doesn't have permissions to do this?  Is there a
>way that this can be done?

You should really ask this question on a CGI newsgroup.  Unless your CGI
is running as you (cgiwrap or apache suexec option) your CGI likely does
not have permission to write to a file unless it already exists with 666
permission (or at least 606) or cannot create a new file unless the dir
has 777 (or maybe 707) permission (a bad idea since anyone could write
to it from their CGI).

Most systems ignore suid for scripts (not sure about suidperl scripts), so
you may need an suid C wrapper.  Not sure where you can get an example of
this.  The old perl4 "Programming perl" had an example, but the current
Perl5 "Programming Perl" book does not.

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Sat, 02 Dec 2000 00:05:53 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Counting bits.
Message-Id: <t2gf7152fcjra2@corp.supernews.com>

Michael Guenther (MiGuenther@lucent.com) wrote:
: my $str = "100110101";
: my $count = 0;
: 
: while ($str=~/1/g){
:    $count ++;
: }
: print $count;

Sure seems like a long way to do

  my $str   = '100110101';
  my $count = $str =~ tr/1//;
  print $count;

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "There is no dark side of the moon really.  Matter
   |   of fact, it's all dark."  - Pink Floyd


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

Date: Sat, 02 Dec 2000 01:37:07 GMT
From: Pasquale <pdmos23@geocities.com>
Subject: DBI question
Message-Id: <3A285354.FED6A358@geocities.com>

I am creating database to register runners for a race using Access, CGI
and DBI on a Windows 2000/NT server, and I have alot of values.  My
question is, when using INSERT INTO table (field1, field2, ...) VALUES
(value1, value2, ....), is there anyway I can break the field and value
names into 2 shorter lines instead of one long line? Like the examples
below.
Example:
my $sth = $dbh->prepare( "
  INSERT INTO 1to11rnrs (name1, email1, gender1, age1, adr1, pc1,
shirt1, name2 email2, gender2, age2, adr2, pc2, shirt2)
  VALUES ('$name1', '$email1', '$gender1', '$age1', '$adr1', '$pc1',
'$shirt1', '$name2', '$email2', '$gender2', '$age2', '$adr2', '$pc2',
'$shirt2')
 " );
$sth->execute() || die "Can't execute SQL statement: $DBI::errstr\n";

(PS: I tried the example below, but it would not work.  Is there another
way?)

my $sth = $dbh->prepare( "
  INSERT INTO 1to11rnrs (name1, email1, gender1, age1, adr1, pc1,
shirt1,
                                          name2 email2, gender2, age2,
adr2, pc2, shirt2)
  VALUES ('$name1', '$email1', '$gender1', '$age1', '$adr1', '$pc1',
'$shirt1',
                   '$name2', '$email2', '$gender2', '$age2', '$adr2',
'$pc2', '$shirt2')
 " );
$sth->execute() || die "Can't execute SQL statement: $DBI::errstr\n";

Thanks,
Pasquale



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

Date: 01 Dec 2000 20:55:50 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: DBI question
Message-Id: <m38zpzsi1l.fsf@mumonkan.sunstarsys.com>

Pasquale <pdmos23@geocities.com> writes:

> I am creating database to register runners for a race using Access, CGI
> and DBI on a Windows 2000/NT server, and I have alot of values.  My
> question is, when using INSERT INTO table (field1, field2, ...) VALUES
> (value1, value2, ....), is there anyway I can break the field and value
> names into 2 shorter lines instead of one long line?

Use HERE documents, bindings (?) and multiple executes on the
same (prepared) statement handler- 
they're tailor-made for your situation:

# untested code follows

my $sth = $dbh->prepart(<<SQL);
INSERT INTO 1to11rnrs 
(name1, email1, gender1, age1, adr1, pc1,
shirt1, name2, email2, gender2, age2, adr2, pc2, shirt2)
VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
SQL

my @values = ( $name1, 
               $email1,
               $gender1,
               # [...]
               $shirt2,
            );

$sth->execute(@values) 
   or die "Can't execute SQL statement: $DBI::errstr\n";

You don't have to prepare your SQL statement again if you
are reusing it, so just change the @values array and call

$sth->execute(@values)
   or die "Can't execute SQL statement: $DBI::errstr\n";

again until you're done with this SQL statement.

Check

% perldoc DBI

for more details on how this works.

HTH
-- 
Joe Schaefer



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

Date: 02 Dec 2000 01:12:02 +0000
From: nobull@mail.com
Subject: Re: Definition of solid block symbol
Message-Id: <u9g0k77hjx.fsf@wcl-l.bham.ac.uk>

gallantknave <gallantknave@my-deja.com> writes:

> I've replaced newlines with <br> in a cgi script and when it shows up
> in the file, I get a solid block followed by <br>. Can anyone tell me
> what the symbol of a solid block stands for and why it happens?

In some text editors under some operating systems the solid block is
used to represent a non-printable character.  (This has nothing to do
with Perl).

> As in:  $item =~ s/\n/\<br\>/g;

If you do this on an operating system where the EOL marker is CR-LF
you'll replace the LF with <BR> leaving CR <BR>.  The aforementioned
text editor will therefore display this as a solid block and a <BR>.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Sat, 02 Dec 2000 01:45:01 GMT
From: acroapl@my-deja.com
Subject: Getting a File From A Different Server...
Message-Id: <909k6u$9d5$1@nnrp1.deja.com>

I'm making a CGI Program (in perl of course), and I want to display to
the user if they have the most current version of the program.  To do
this I would have a text file with the current version on my server.
The user gets that file and compares it to his version and displays it
displays if it needs to be upgraded or not.

Is this possible?  I think I heard about this once, but I've been
looking for tutorials on how to do this to no avail.  Thanks in advance.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 1 Dec 2000 18:43:25 -0500
From: "Diana Richardson" <dfryberg@kent.edu>
Subject: Help Me, Please
Message-Id: <909erb$omm$1@usenet.kent.edu>

I am totally at my wits end and I know you don't really like helping with
homework but I'm stuck. I've tried every combination I know and I keep
getting error messages I can't find in any book. The professor is so bad
when you ask for an explanation he just confuses you more. Well I won't even
go there.

I need to write a program that will create this pattern:

aba, abba, abbba, etc.

Simple right? HaHaHaHaHa

Well this is what I've done in many variations, I'll just give you the
latest because I actually get the same error with every change:

#!/usr/bin/perl -w

$firstpart = ab
$addb = +b
$lastpart = a

print ($firstpart . $addb + $lastpart);

This is my error message:

Unquoted string "a" may clash with future reserved word at abba line 7.
syntax error at abba line 7, near "a

print"
Execution of abba aborted due to compilation errors.






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

Date: Sat, 2 Dec 2000 01:23:09 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Help Me, Please
Message-Id: <slrn92gjnl.gng.efflandt@efflandt.xnet.com>

On Fri, 1 Dec 2000 18:43:25 -0500, Diana Richardson <dfryberg@kent.edu> wrote:
>I am totally at my wits end and I know you don't really like helping with
>homework but I'm stuck. I've tried every combination I know and I keep
>getting error messages I can't find in any book. The professor is so bad
>when you ask for an explanation he just confuses you more. Well I won't even
>go there.
>
>I need to write a program that will create this pattern:
>
>aba, abba, abbba, etc.
>
>Simple right? HaHaHaHaHa
>
>Well this is what I've done in many variations, I'll just give you the
>latest because I actually get the same error with every change:
>
>#!/usr/bin/perl -w
>
>$firstpart = ab
>$addb = +b
>$lastpart = a
>
>print ($firstpart . $addb + $lastpart);
>
>This is my error message:
>
>Unquoted string "a" may clash with future reserved word at abba line 7.
>syntax error at abba line 7, near "a

It means what it says.  You actually forgot to quote all of your string
values, but you also forgot to terminate each statement with ";", so Perl
thinks your script is all one statement.

But I don't think this routine will do what you expect it to anyway.  
You can append (.) strings, but not add (+) them.

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Fri, 1 Dec 2000 19:16:20 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Help Me, Please
Message-Id: <slrn92gfqk.be7.tadmc@magna.metronet.com>


Please put the subject of your post in the Subject of your post.


Diana Richardson <dfryberg@kent.edu> wrote:
>I am totally at my wits end

>$firstpart = ab

>Unquoted string "a" may clash with future reserved word at abba line 7.
>syntax error at abba line 7, near "a


This is the identical article that you posted here 2 days ago.

perl itself told you that you have a problem with quoting.

All 4 of the followups to your article from the other day 
told you that you have a problem with quoting.

So why are you back without fixing your problem with quoting?

Since everybody can see that you ignore all followups anyway, 
what is the point in responding to you at all? You won't
hear what is said.

If you haven't picked it up after being told 5 times, you _deserve_
to get a bad grade. Give up. Change majors.


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


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

Date: 01 Dec 2000 19:26:15 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: how do i escape from perldoc
Message-Id: <m3d7fbsm6w.fsf@mumonkan.sunstarsys.com>

Jeff Zucker <jeff@vpservices.com> writes:

> Tony Curtis wrote:
> > 
> > On Fri, 01 Dec 2000 11:36:28 -0800,
> > Jeff Zucker <jeff@vpservices.com> said:
> > 
> >> Joe Schaefer wrote:
> >
> >>> vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse) writes:
> >
> >>>> Tad McClellan <tadmc@metronet.com> wrote:
> > 
> >>>>> man more 
> >
> >>>> man less
> >
> >>> That's more or less right.
> >
> >> Oh man!
> > 
> > Is that from PG Wodehouse?
> 
> Beckett I think.  At least he deals with garbage collection similarly to
> the way Perl does.
 
Indeed-

http://compare.upol.cz/irish/Swork/Beckett/CH_5.HTM

;-)

-- 
Joe Schaefer



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

Date: Sat, 02 Dec 2000 00:35:49 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: howto specify command line options
Message-Id: <t2ggv57dap0n39@corp.supernews.com>

In article <7nVV5.4377$fy2.331751@news.soneraplaza.nl>,
    paul <remi@multiweb.nl> wrote:

: i would like to specify commandline options in a perl script
: 
: for example ./test.pl -i <ip_addr> -h <host_name> etc etc
: 
: but i cant seem to find info on how to setup the options -i, -h

Use one of the Getopt::* modules or browse the PPT[*] and find an
argument parser that you like.

[*] <URL:http://language.perl.com/ppt/what.html>

Greg
-- 
> You're a big burly OO dude. Why aren't you programming in Python? 
When you live in Australia, you learn to be wary of snakes. 
    -- Damian Conway speaking of Python


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

Date: Fri, 01 Dec 2000 23:20:53 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Improve code with RegEx
Message-Id: <x74s0nafu1.fsf@home.sysarch.com>

>>>>> "JBW" == John Boy Walton <johngros@Spam.bigpond.net.au> writes:

  JBW>  if ($line =~ /<BODY>/){
  JBW> #$` is the string preceding the match, $& is the match
  JBW>     $String_A = $`.$&;
  JBW> #$' is the string following the match
  JBW>     $String_B = $';

don't use $&, $' and $` as they will slow down ALL other regexes. use
parens to grab which will only affect those regexes.

<excise of total jeopardy quote>

don't do that either. edit the quotes and reply AFTER it.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: 01 Dec 2000 16:39:59 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Improve code with RegEx
Message-Id: <m33dg722bk.fsf@dhcp11-177.support.tivoli.com>

"Jean" <jean.zoch@utoronto.ca> writes:

> Right now, it steps through a string looking at each position and 3
> positions ahead until it finds "body". It then sets $reached_body to true.
> Then, it continues until it finds the character ">". I am using this code to
> split a string that should contain the HTML tag <BODY> right after the ">".
> The code then makes the two strings using substr.

In general, parsing HTML is tricky.  If you want it to be robust, you
are better of using one of the existing modules that exist for this
purpose (HTML::Parser, HTML::Filter, etc.).

> Is there a better way (for sure!) to do this with regular expressions?

That being said, yes, this is certainly easier to do with a regex.  I'm
too lazy to parse the code you posted, so I'll just base it off of
your request above.  My understanding is that you want to split the
string so that everything up to and including the *first* occurrence of
"<BODY>" is in one string, and everything else is in a second string.

# $line has all of the text:
($header, $body) = $line =~ /^(.*?<BODY>)(.*)/s;


-- 
Ren Maddox
ren@tivoli.com


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

Date: Fri, 1 Dec 2000 16:17:43 -0800
From: Steven Kuo x7914 <skuo@mtwhitney.nsc.com>
Subject: Re: Is there a function like LaTeX's \input ?
Message-Id: <Pine.GSO.4.21.0012011613070.20968-100000@mtwhitney.nsc.com>

On Fri, 1 Dec 2000, Neil Montgomery wrote:

> I would like to split up a Perl program into several parts, for ease
> of editing. Making my own modules would be overkill in my situation.  
> 
> Is there a Perl function which will insert the contents of a file into
> the code (like the LaTeX function \input)? 
> 
> As a trivial example, suppose I had a file called "foo" containing the
> single line: 
> 
>     my($x) = 1;
> 
> and I had a Perl program called "bar" consisting of:
> 
>     #/usr/bin/perl -w
>     use strict; 
> 
>     is_there_such_a_function('foo');
> 
>     print "$x\n";
> 
> Is there such a function that would insert the file "foo" so that
> "bar" would actually run?


Well, you may be able to use: do 'filename'; see perldoc -f do
for details.

Here's a short example:

% cat foo
my $y = 9;
$y + 3;

% cat bar
#! /usr/local/bin/perl

use strict;
use v5.6.0;
use warnings;

my $x;

unless ($x = do 'foo') {
    warn "Couldn't parse file foo: $@" if $@;
    warn "Couldn't do file foo: $!"    unless defined $x;
}


print "After evaluating this code:\n";

open (DOF,'foo') or die ("Could not open foo: $!");
while (my $line = <DOF>) { 
    print $line;
    if (eof(DOF)) { chomp $line; print "We evaluate \$x = $line to
be: $x\n"; }
}
close (DOF) or die ("Could not close foo: $!");


-- 
Steve



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

Date: 01 Dec 2000 18:21:29 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Pattern matching, I need a quick check.
Message-Id: <m3lmtzsp6u.fsf@mumonkan.sunstarsys.com>

Eli the Bearded <elijah@workspot.net> writes:

> In comp.lang.perl.misc, Ren Maddox  <ren.maddox@tivoli.com> wrote:
> > pjgratz@my-deja.com writes:
> > > if(/^([A-Za-z]+\s+\d+\s+\d+\:\d+\:\d|).+POP login for \"(.+)\".+\s
> > > (\d+\.\d+\.\d+.\d+).*$/)
> > This is fine (well, escaping the colons is pointless and having an
> > empty alternation is a strange way to make the timestamp optional, but
> > it works).
> 
> Well, some people might consider it a problem that only one digit
> of the seconds is matched.

That's not the only problem- logins from (fictitious, deranged) 
places like

% nslookup -type=PTR 1.2.3.4

4.3.2.1.in-addr.arpa     'POP login for "root" (localhost) 127.0.0.1'

might befuddle your logfile analysis a bit.
( One might hope that the taint flag is used in 
this script, but I wouldn't bet on it :)

-- 
Joe Schaefer



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

Date: Sat, 02 Dec 2000 00:52:25 GMT
From: ryanwol2000@my-deja.com
Subject: Perl FORMAT into variable?
Message-Id: <909h47$71u$1@nnrp1.deja.com>

Does anyone know how I can create a FORMAT as
shown below, but instead of sending it to STDOUT
(the screen), send it to a variable? I've tried
openning the file handle into an array just like
openning a data file, but no luck.

Here is code to create a simple FORMAT to the
screen:

# Setup the Report screen
format STDOUT_TOP =
@||||||||||||||||||||||||||||||||||||||||||||
                "My Report"
NAME             PHONE NUMBER
---------------------------------------------
 .
format STDOUT =
@<<<<<<<<<<<<<<< @<<<<<<<<<<<
$NAME,$PHONE
 .
$NAME  = "JOE SHMOE";
$PHONE = "555-1212";
write;

I want the same thing as above, but instead of
sending it to the screen, I need it in a variable
or an array. Thank you..


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sat, 02 Dec 2000 00:58:31 GMT
From: ryanwol2000@my-deja.com
Subject: Perl FORMAT Into variable?
Message-Id: <909hfk$7d0$1@nnrp1.deja.com>

Is it possible to create a REPORT or FORMATTED TEXT where the output
goes into a variable instead of STDOUT? I've tried to read the file
handle into an array or variable just like opening a file from disk but
it does not seem to work for me. Below is the example of the report:

# Setup the Report screen
format STDOUT_TOP =
@||||||||||||||||||||||||||||||||||||||||||||
                "My Report"
NAME             PHONE NUMBER
---------------------------------------------
 .
format STDOUT =
@<<<<<<<<<<<<<<< @<<<<<<<<<<<
$NAME,$PHONE
 .
$NAME  = "JOE SHMOE";
$PHONE = "555-1212";
write;

The output from above gets sent to STDOUT, I need it in a perl variable.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 1 Dec 2000 23:01:09 GMT
From: rrknight@usgs.gov
Subject: Re: RE:Automation
Message-Id: <909ajl$e4j$1@qvarsx.er.usgs.gov>

I have managed to get the process to run (simple DOS style program).  But, 
When the program rns, it is waiting on commands from the user which I 
assume can be fed through the PERL script, but have yet to determine the 
correct method for this.  Does anyone have any examples?



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

Date: 02 Dec 2000 00:59:12 +0000
From: nobull@mail.com
Subject: Re: Reading file into array.
Message-Id: <u9hf4n7i5b.fsf@wcl-l.bham.ac.uk>

tadmc@metronet.com (Tad McClellan) writes:

> nobull@mail.com <nobull@mail.com> wrote:
> >"John Boy Walton" <johngros@Spam.bigpond.net.au> writes as thought
> >this is the middle of a thread, but it isn't this is the start of a
> >new thread.
> >
> 
> >>   $flag = "set";
> >
> >When using a variable to act as a boolean flag it is sensible to adopt
> >the conventions of the language that you are using.  In Perl you
> >should use '' and 1 for true and false.
> 
> 
>    s/true and false/false and true/;

Hmmm.. yes.  Go ahead, mock the afflicted.

> >>   $flag ="not set";
> >
> >$flag = 0;
> 
> 
> Errr, so which is it?
> 
> Empty string or zero for false?  ( I vote for zero )

Empty string, zero, undef - all are Perlish conventions.  I as you can
see am I foating voter.  So much so I change (loosing?) my mind as I
go along.

Having another bad day.  Go on lay into me - I deserve it.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Sat, 2 Dec 2000 11:32:09 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: regex not matching
Message-Id: <qKYV5.6$UL2.3836@vic.nntp.telstra.net>

"Ren Maddox" <ren.maddox@tivoli.com> wrote in message
news:m3hf4o2l14.fsf@dhcp11-177.support.tivoli.com...
> wyzelli@yahoo.com (Wyzelli) writes:
>
> > The regex to skip the $0.00 lines was /\$0\.00$/  Which failed to match.
> >
> > To get it to work, I had to use m/\$0\.00$/.
> >
> > I thought the m was optional when the regex delimiter was a slash.
>
> This worked fine for me:
>
> #!/usr/local/bin/perl
> while (<DATA>) {
>   print unless /\$0\.00$/;
> }
> __DATA__
> C     Around to it                       aroundto       $22.23
> C     Around to it                       aroundto       $0.00
> __END__
>
> Outputs:
> C     Around to it                       aroundto       $22.23
>
> So let's see your code...
>

OK, here is a sample which I just did on my home PC which dislpays exactly
the same behaviour.

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

open (IN, 'c:/perl/scripts/01122000.txt') or die "cant $!";
while (<IN>){
 next if m/\$0\.00$/;
 print;
}

With the m, it works OK, without, it doesn't.

Sample data from the file: (simple text file with just spaces between
fields).

Type  Charge to                          Username      Charge

C     Around to it                       aroundto       $22.23
C     BBQ King                           gergav         $14.22
C     BedPost                            bedpost        $10.00
C     BedPost                            bedposti       $5.00
C     Betapave                           betapave       $30.45
C     Big Dreams                         bigdream       $0.00
C     CRUC                               cougars        $50.46
C     Central                             central       $180.00
C     EC&E                               ecande         $16.80
C     ECHO                               catrin         $18.84
C     Enzed                              enzed          $0.00

Since you have not experienced any problem with the above, I can only
conclude that there may be an issue with the Perlbuilder IDE and running
with strict.

Thanks for your input. (Tad too)  :)

Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';





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

Date: Fri, 1 Dec 2000 17:41:22 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: strings with a minus
Message-Id: <slrn92ga8i.as9.tadmc@magna.metronet.com>

John Boy Walton <johngros@Spam.bigpond.net.au> wrote:

>I have a string 


You think you have a string.

What you think is a string, perl thinks is Perl code.

Where is the code that generates the message?


>with a minus sign in it when I copy the scalar into an array
>element I am getting an 'isn't numeric subtraction error'.
>How do I escape the minus so the value can be passed?


Nobody can know what is wrong with your code because you
did not show anybody your code.

Show somebody the code.


>Or is it just a warning and if run without the -w would go through?


It "goes through", whatever that means, regardless of whether
or not you have warnings turned on.

Warnings do not affect the operation of your program.

If it "works" without warnings enabled, it will "work" 
with warnings enabled and vice versa.

But if it generates warning messages, it is very likely
to not "work" :-)


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


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

Date: 01 Dec 2000 16:41:21 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: strings with a minus
Message-Id: <m3y9xzzrvy.fsf@dhcp11-177.support.tivoli.com>

"John Boy Walton" <johngros@Spam.bigpond.net.au> writes:

> I have a string with a minus sign in it when I copy the scalar into an array
> element I am getting an 'isn't numeric subtraction error'.
> How do I escape the minus so the value can be passed?
> Or is it just a warning and if run without the -w would go through?

Please show the exact code you are using.  If the data is a string, it
should not normally be evaluated, so it shouldn't look like
subtraction.

If you are trying to do something like:

$hash{my-value} = "foo";

then you will need to quote the key:

$hash{"my-value"} = "foo";

-- 
Ren Maddox
ren@tivoli.com


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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

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

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


------------------------------
End of Perl-Users Digest V9 Issue 5013
**************************************


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