[15569] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2982 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 8 18:15:54 2000

Date: Mon, 8 May 2000 15:15:28 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <957824128-v9-i2982@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 8 May 2000     Volume: 9 Number: 2982

Today's topics:
    Re: Proper use of resources (was Re: more regexp madnes <nospam@devnull.com>
    Re: Proper use of resources (was Re: more regexp madnes <uri@sysarch.com>
    Re: Proper use of resources (was Re: more regexp madnes (Randal L. Schwartz)
    Re: push-ing into a hash (Tad McClellan)
    Re: push-ing into a hash <tony_curtis32@yahoo.com>
        Reading MS-Word Doc via PERL <mirak63@yahoo.com>
    Re: reg.expr. for correct parentheses? <gellyfish@gellyfish.com>
    Re: search and replace meta tags in perl - newbie quest <jamalone@earthlink.net>
    Re: search and replace meta tags in perl - newbie quest <lr@hpl.hp.com>
    Re: search and replace meta tags in perl - newbie quest <jamalone@earthlink.net>
    Re: search and replace meta tags in perl - newbie quest (Tad McClellan)
    Re: search and replace meta tags in perl - newbie quest <flavell@mail.cern.ch>
    Re: search and replace meta tags in perl - newbie quest (Tad McClellan)
        Sort/Remove Duplicates from Database jzoetewey@my-deja.com
    Re: Sort/Remove Duplicates from Database <jeff@vpservices.com>
        splitting into a hash <rbbdsb@earthlink.net>
        Syntax for passing  parameters from command line, then  <news@access-management.com>
    Re: Syntax for passing  parameters from command line, t <tony_curtis32@yahoo.com>
    Re: trouble with a conversion <billy@arnis-bsl.com>
    Re: trouble with a conversion <flavell@mail.cern.ch>
        Using comma separators in decimal formatting in "printf qazwart@my-deja.com
    Re: Using comma separators in decimal formatting in "pr (Teodor Zlatanov)
    Re: Using comma separators in decimal formatting in "pr <lr@hpl.hp.com>
    Re: Using comma separators in decimal formatting in "pr <latsharj@my-deja.com>
    Re: Using comma separators in decimal formatting in "pr (Bart Lateur)
        Win32::ODBC / creating a new database file <jrathmann@gmx.de>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 8 May 2000 21:21:19 GMT
From: The WebDragon <nospam@devnull.com>
Subject: Re: Proper use of resources (was Re: more regexp madness extracting data from files.)
Message-Id: <8f7b4f$1a9$0@216.155.32.56>

In article <m1vh0ptelx.fsf@halfdome.holdit.com>, merlyn@stonehenge.com 
(Randal L. Schwartz) wrote:

 | >>>>> "The" == The WebDragon <nospam@devnull.com> writes:
 | 
 | The> what would be the most elegant and efficient means to accomplish 
 | this in 
 | The> perl?
 | 
 | Well, I'd start by writing *something* that at least attempts to do
 | the problem.  Where I got stuck, I'd stare at the manuals for a while,
 | and if I got really stuck, I'd turn to my buddies, and if they didn't
 | know, I'd pop up at a local PerlMongers meeting (find one or start one
 | via www.pm.org), and then if none of that worked, I pose a well-formed
 | question (including relevant snippets of code, not the whole program)
 | to comp.lang.perl.misc or comp.lang.perl.moderated, including a return
 | email address so that short replies or interaction can be had directly
 | with me in private.
 | 
 | After getting a working program, I'd continue to review relevant
 | documentation, and perhaps use benchmarking to see where it was
 | spending all of its time, maybe even writing parts in C to get the
 | most efficiency, although that's often not necessary.
 | 
 | Since you haven't done any of that yet, it's gonna be a long road
 | to travel.
 | 
 | CLP.M* is just a resource, but more of a "I've done my own thinking
 | and checked everywhere else" resource.  Please don't abuse it.  Post
 | with a valid email address (spamblocked if you must).  If you had done
 | that, I wouldn't need to needle you in public - this could have been a
 | private message.

fine, here goes: 
-=-begin script-=-
#!perl
use strict;
use diagnostics -verbose;
use File::Spec;

my $inputDir = File::Spec->catfile( File::Spec->curdir(), 'input_files', 
'');
my @filesList; 
my $grabFile;
my @dataList;

opendir(DIR, $inputDir) || die "can't opendir $inputDir: $!";
    @filesList = readdir(DIR);
closedir DIR;

foreach my $flist (@filesList) {
$grabFile = $inputDir . $flist;
    open(GRAB, "<$grabFile") or die ('Cannot open file ' . $grabFile . 
"$!");
#   print 'Successful open of '. $grabFile ."\n";
    while(<GRAB>) {
        next unless /^\Qmaps[i++] = new Map(\E([^)]+)/;
  @dataList .= "$1 \n";
#       print $1 . "\n";
    }
    close (GRAB);
};

open(OUT, ">MyCompleteList.txt") or die(' Cannot open output file ' . 
$!);
    foreach my $text (@dataList) {
        print OUT $text . "\n";
    };
close (OUT);
-=-end script-=-

the line 
      @dataList .= "$1 \n";

generates an error of 

# Can't modify private array in concatenation, near ""$1 \n";"
File '[snip]:ratings:fileGrab.pl'; Line 21

which perldiag.pod describes as 

    Can't modify %s in %s   

(F) You aren't allowed to assign to the item indicated, or otherwise try 
to change it, such as with an auto-increment. 

and the question is : why not?

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


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

Date: Mon, 08 May 2000 21:45:46 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Proper use of resources (was Re: more regexp madness extracting data from files.)
Message-Id: <x7zoq0vhpy.fsf@home.sysarch.com>

>>>>> "TW" == The WebDragon <nospam@devnull.com> writes:

  TW>       @dataList .= "$1 \n";

  TW> # Can't modify private array in concatenation, near ""$1 \n";"
  TW> File '[snip]:ratings:fileGrab.pl'; Line 21

  TW> (F) You aren't allowed to assign to the item indicated, or otherwise try 
  TW> to change it, such as with an auto-increment. 

  TW> and the question is : why not?

simple. you are applying the scalar assignment operator .= to an
array. it logically expands to:

	@dataList = @dataList . "$1 \n" ;

which make no sense as you are assigning a single element to the list
which is the concatenation of the number of elements in the list and
some string. so you are accessing its count and changing the count in
one expression so perl says "don't do that!!"

you probably meant to use push:

	push @dataList, "$1 \n" ;


also the rest of the code has some areas which can be improved
stylistically.

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: 08 May 2000 15:04:16 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Proper use of resources (was Re: more regexp madness extracting data from files.)
Message-Id: <m1bt2gog0v.fsf@halfdome.holdit.com>

>>>>> "Randal" == Randal L Schwartz <merlyn@stonehenge.com> writes:

Randal> Post with a valid email address (spamblocked if you must).  If
Randal> you had done that, I wouldn't need to needle you in public -
Randal> this could have been a private message.

I apologize for this part of the message.  Your spamblocked address
is in your .sig block.  Silly me for not looking there.  Sorry.

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


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

Date: Mon, 8 May 2000 13:07:13 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: push-ing into a hash
Message-Id: <slrn8hdt21.d6h.tadmc@magna.metronet.com>

On 08 May 2000 11:24:52 -0500, Tony Curtis <tony_curtis32@yahoo.com> wrote:
>>> On Mon, 8 May 2000 17:56:40 +0200,
>>> Thomas Schmitt <su1005@mailserv.uni-giessen.de> said:
>
>> I tried a push-statement like this:
>
>>           push (@hash_name{$idx}, $scalar);
>
>> It doesn't work. Can anybody help me out?
>
>You have to cast the hash key into an array context,
>
>    push @{$hash_name{$idx}}, $scalar;


That is the correct way to do it, but the sentence before it
is misleading.

You are not "casting" the hash key ($idx is the hash key). 

You are de-referencing the hash _value_.

There is no such thing as "array context", there is 
"list context" though, but it does not have anything to
do with the problem, and your change does not change
_any_ context.  The context is determined by the
_operator_ (push).


So, rephrasing it:

   You have to de-reference the hash value into an array.


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


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

Date: 08 May 2000 13:16:43 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: push-ing into a hash
Message-Id: <87snvsq54k.fsf@shleppie.uh.edu>

>> On Mon, 8 May 2000 13:07:13 -0400,
>> tadmc@metronet.com (Tad McClellan) said:

> On 08 May 2000 11:24:52 -0500, Tony Curtis
> <tony_curtis32@yahoo.com> wrote:
>>
>> You have to cast the hash key into an array context,
>> 
>> push @{$hash_name{$idx}}, $scalar;

> That is the correct way to do it, but the sentence
> before it is misleading.
> You are not "casting" the hash key ($idx is the hash
> key).
> You are de-referencing the hash _value_.

You got me.  I phrased it all horribly wrong.  I'll cancel
my article in fact.

tony


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

Date: Mon, 08 May 2000 20:06:01 GMT
From: Karim Wall <mirak63@yahoo.com>
Subject: Reading MS-Word Doc via PERL
Message-Id: <8f76ms$v14$1@nnrp1.deja.com>

Hello,

Sorry for the stupid question...
How would one read directly from an
MS-WORD document using PERL.

I have about 300 .doc files to scan through and
I don't relish opening each of them within WORD
and doing a SAVE AS Text.

Is there an EZ way?

Thanks,
Karim Wall
mirak63@yahoo.com



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


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

Date: 5 May 2000 19:45:59 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: reg.expr. for correct parentheses?
Message-Id: <8ev4t7$bt9$1@orpheus.gellyfish.com>

On 3 May 2000 16:20:09 GMT Ilya Zakharevich wrote:
> [A complimentary Cc of this posting was sent to Tad McClellan
> <tadmc@metronet.com>],
> who wrote in article <slrn8h094h.7bi.tadmc@magna.metronet.com>:
>> >I'm trying to get a list of all correctly parenthesized expressions from
>> >a string.
> 
>>    Perl FAQ, part 6:
>> 
>>       "Can I use Perl regular expressions to match balanced text?"
> 
> And keep in mind that this entry of the FAQ is approximately of same
> validity as a lot of the others: close to zilch.
> 

I would be interested to know what the "bizarre and experimental features
in the development-track releases of Perl" are though.  I am assuming
in fact that this refers to the last 4 extended features described in
perlre and that this FAQ hasnt been updated for 5.6.0 .  There seems to
be an implication in perlre that these features might not be retained if
people dont find them useful so perhaps the FAQ should be updated with
an example using them .

/J\
-- 
When I first heard that Marge was joining the police academy, I thought
it would be fun and zany, like that movie -- Spaceballs. But instead it
was dark and disturbing. Like that movie -- Police Academy.
-- 
fortune oscar homer


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

Date: Mon, 08 May 2000 18:46:43 GMT
From: "Jason Malone" <jamalone@earthlink.net>
Subject: Re: search and replace meta tags in perl - newbie question
Message-Id: <nYDR4.38784$x4.1273346@newsread1.prod.itd.earthlink.net>

Try this

s/<HEAD>/<HEAD<meta name\=keywords content\=\"dejanews usenet newsgroup
articles search query discussion\">/g

It is important to escape certain characters like quotes and equal signs.

Jason Malone

"Hilary Cotter" <hpcotter@my-deja.com> wrote in message
news:8f6qg2$g48$1@nnrp1.deja.com...
> Hi
>
> I am trying to do a search and replace of <HEAD> with <HEAD<meta
name=keywords content="dejanews usenet newsgroup articles search query
discussion">
>
> can anyone write the syntax for the search and replace function I
> should use in Perl.
>
> ie s/<HEAD>/<HEAD<meta name=keywords content="dejanews usenet newsgroup
articles search query discussion">/g
>
> I can't get this to work.
>
> Thanks in advance
>
>
> Hilary Cotter
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>




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

Date: Mon, 8 May 2000 12:34:21 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: search and replace meta tags in perl - newbie question
Message-Id: <MPG.1380b6983609443298aa22@nntp.hpl.hp.com>

In article <nYDR4.38784$x4.1273346@newsread1.prod.itd.earthlink.net> on 
Mon, 08 May 2000 18:46:43 GMT, Jason Malone <jamalone@earthlink.net> 
says...
> Try this
> 
> s/<HEAD>/<HEAD<meta name\=keywords content\=\"dejanews usenet newsgroup
                ^
                >
> articles search query discussion\">/g
> 
> It is important to escape certain characters like quotes and equal signs.

Wrong on each of those.  The only characters that must be escaped in the 
substitution string are $, @, \, and the regex delimiter.

And the /g flag isn't likely to do much.  How many '<HEAD>' tags do you 
think there will be?

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


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

Date: Mon, 08 May 2000 20:38:35 GMT
From: "Jason Malone" <jamalone@earthlink.net>
Subject: Re: search and replace meta tags in perl - newbie question
Message-Id: <fBFR4.38994$x4.1283656@newsread1.prod.itd.earthlink.net>

OK Larry,

Why don't you post a solution instead of just a slap on the wrist.

Jason

"Larry Rosler" <lr@hpl.hp.com> wrote in message
news:MPG.1380b6983609443298aa22@nntp.hpl.hp.com...
> In article <nYDR4.38784$x4.1273346@newsread1.prod.itd.earthlink.net> on
> Mon, 08 May 2000 18:46:43 GMT, Jason Malone <jamalone@earthlink.net>
> says...
> > Try this
> >
> > s/<HEAD>/<HEAD<meta name\=keywords content\=\"dejanews usenet newsgroup
>                 ^
>                 >
> > articles search query discussion\">/g
> >
> > It is important to escape certain characters like quotes and equal
signs.
>
> Wrong on each of those.  The only characters that must be escaped in the
> substitution string are $, @, \, and the regex delimiter.
>
> And the /g flag isn't likely to do much.  How many '<HEAD>' tags do you
> think there will be?
>
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Laboratories
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com
>




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

Date: Mon, 8 May 2000 16:18:46 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: search and replace meta tags in perl - newbie question
Message-Id: <slrn8he896.det.tadmc@magna.metronet.com>

On Mon, 08 May 2000 16:37:25 GMT, Hilary Cotter <hpcotter@my-deja.com> wrote:
>
>I am trying to do a search and replace of <HEAD> with <HEAD<meta
                                                       ^^^^^^

That does not look like valid HTML to me.

Did you mean "<HEAD><meta" there instead?
                   ^

>name=keywords content="dejanews usenet newsgroup articles search query
>discussion">
>
>can anyone write the syntax for the search and replace function I
>should use in Perl.


Yes, *you* can  :-)


>ie s/<HEAD>/<HEAD<meta name=keywords content="dejanews usenet newsgroup
>articles search query discussion">/g


That looks fine (assuming the string is in $_ and it was supposed
to be all on one line).


>I can't get this to work.


Your problem is somewhere else.

Since you haven't shown any of your code, we cannot help
you fix it.


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


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

Date: Mon, 8 May 2000 23:39:35 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: search and replace meta tags in perl - newbie question
Message-Id: <Pine.GHP.4.21.0005082339130.3709-100000@hpplus01.cern.ch>

On Mon, 8 May 2000, Jason Malone wrote:

> OK Larry,
> 
> Why don't you post a solution instead of just a slap on the wrist.

and the killfile gains yet another entry...




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

Date: Mon, 8 May 2000 16:30:45 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: search and replace meta tags in perl - newbie question
Message-Id: <slrn8he8vl.dia.tadmc@magna.metronet.com>


[ Please put your comments *following* the quoted text that
  you are commenting on.

  Please do NOT quote text that you are not commenting on.

  Please do not quote .sigs

  Please do see the articles posted to   news.announce.newusers

  Jeopardectomy performed.
]


On Mon, 08 May 2000 18:46:43 GMT, Jason Malone <jamalone@earthlink.net> wrote:
>"Hilary Cotter" <hpcotter@my-deja.com> wrote in message
>news:8f6qg2$g48$1@nnrp1.deja.com...
>>
>> I am trying to do a search and replace of <HEAD> with <HEAD<meta
>name=keywords content="dejanews usenet newsgroup articles search query
>discussion">
>>
>> can anyone write the syntax for the search and replace function I
>> should use in Perl.
>>
>> ie s/<HEAD>/<HEAD<meta name=keywords content="dejanews usenet newsgroup
>articles search query discussion">/g
>>
>> I can't get this to work.


>Try this
>
>s/<HEAD>/<HEAD<meta name\=keywords content\=\"dejanews usenet newsgroup
>articles search query discussion\">/g
>
>It is important to escape certain characters 


Yes it is.


>like quotes and equal signs.


No it isn't.



You only need to quote characters that have a meta (special)
meaning.

quotes and equal signs are not meta in regexs, so escaping
them accomplishes nothing (except make your code harder to
read, which is bad).


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


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

Date: Mon, 08 May 2000 19:49:32 GMT
From: jzoetewey@my-deja.com
Subject: Sort/Remove Duplicates from Database
Message-Id: <8f75o6$tta$1@nnrp1.deja.com>

I'm relatively new to Perl, and have a small amount of experience in
other programming languages.

I'm currently trying to create a program that will allow me to sort and
remove duplicates from information derived from a database.

The information will be in fixed width columns (first name is at 10-19,
last name starts at 20-39, company at...).

I'm assuming that I'll use substr to read the field I want to sort by
(for example: address) and the record number into some kind of array.
I'll then sort by the field (address, name, whatever...).  After things
are sorted, I'll use the order the record number ends up in to determine
 what order the records should be in in the finished file.

My questions go like this:

1. Is that a good strategy for the program?
2. What kind array should I be putting the field and record number into?
 Associative? A multi-dimensional array?
3. Would it be better to bring the whole database into an array at once
rather than just two fields?

Feel free to include any tips that you think might not be obvious to a
beginner...

Jim Zoetewey


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


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

Date: Mon, 08 May 2000 13:48:05 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Sort/Remove Duplicates from Database
Message-Id: <39172805.F0090DD3@vpservices.com>

jzoetewey@my-deja.com wrote:
> 
> I'm relatively new to Perl, and have a small amount of experience in
> other programming languages.
> 
> I'm currently trying to create a program that will allow me to sort and
> remove duplicates from information derived from a database.
> 
> The information will be in fixed width columns (first name is at 10-19,
> last name starts at 20-39, company at...).
> 
> I'm assuming that I'll use substr to read the field I want to sort by
> (for example: address) and the record number into some kind of array.
> I'll then sort by the field (address, name, whatever...).  After things
> are sorted, I'll use the order the record number ends up in to determine
>  what order the records should be in in the finished file.

Yes, those are all things you could do, though unpack would probably be
better than susbtr.  If you want a differnt method, the DBD::RAM module
lets you treat any fixed-width file as a database and say things like
"SELECT DISTINCT * FROM table WHERE company = 'acme' ORDER BY address"
which would remove duplicates, select based on a criterion, and sort it
into an order in one step without messing around with arrays or cooking
up your own sorting routines.

-- 
Jeff


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

Date: Mon, 08 May 2000 21:29:57 GMT
From: "rbbdsb" <rbbdsb@earthlink.net>
Subject: splitting into a hash
Message-Id: <plGR4.39085$x4.1288569@newsread1.prod.itd.earthlink.net>

Hi,
  I've got a long variable length string that I want to read as data pairs
and  stuff into a hash.  The pattern would be something like:

Data
field value field1 value1 field2 value2 field3 value3 ...

Code
split();  # or some variation there of
$StringCount++;
$MyHash{$StringCount}{$field} = value;
foreach my $value( keys %{$MyHash{StringCount}{$field}} )

  print "$field, $value, $StringCount, $MyHash{$StringCount}{$field}\n";
}

I've been trying to accomplish this with split, but am having trouble
figuring out how to pull the data as a field/value pair.  The number of
pairs varies with every line, so I can't do things like

 my ($field1, $value1, $field2, $value2) = split;

Anyone have any thoughts?

TIA,
Russ




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

Date: Mon, 8 May 2000 14:13:58 -0700
From: "Sean Scannell" <news@access-management.com>
Subject: Syntax for passing  parameters from command line, then interpreting them?
Message-Id: <Z5GR4.674$GB2.331870@news.pacbell.net>

I found examples of passing parameters to a subroutine, and passing file
names using argv, but not straight passing of parameters from a command
line.  GetOpts looks like overkill.
I figured passing :

Test.pl -parm1 - parm2

Then interpreting

$str1 = @_[0];
$str2 = @_[1];

but I guess I have it wrong.




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

Date: 08 May 2000 16:24:43 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Syntax for passing  parameters from command line, then interpreting them?
Message-Id: <87hfc8pwf8.fsf@shleppie.uh.edu>

>> On Mon, 8 May 2000 14:13:58 -0700,
>> "Sean Scannell" <news@access-management.com> said:

> I found examples of passing parameters to a subroutine,
> and passing file names using argv, but not straight
> passing of parameters from a command line.  GetOpts
> looks like overkill.  I figured passing :

> Test.pl -parm1 - parm2

> Then interpreting

> $str1 = @_[0]; $str2 = @_[1];

> but I guess I have it wrong.

I don't think the various getopt routines/modules are
overkill.  They certainly take some of the problem away
from you the writer of code.

I usually use Getopt::Long because I find that I often
start adding in more options as code develops.  Blame it
on a lack of planning if you want :-)

So I'd write something along the lines of:

    use Getopt::Long;
    my %options;
    GetOptions('v' => \$options{verbose},      # short and long option forms
	       'verbose' => \%options{verbose})
	or die "....";

And then access the various cmd line options passed in as
$options{whatever}.  @ARGV by this time holds the
non-option cmdline arguments.

So for "test.pl -parm1 -- parm2" I'd have

    $options{parm1}

defined and then after GetOptions()

    @ARGV == ('parm2')

which I could get at as

    my ($arg) = @ARGV;
or
    my $arg = shift;

hth
t


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

Date: Mon, 08 May 2000 17:58:07 GMT
From: Ilja <billy@arnis-bsl.com>
Subject: Re: trouble with a conversion
Message-Id: <8f6v75$lq3$1@nnrp1.deja.com>

In article <u9aei1geqg.fsf@wcl-l.bham.ac.uk>,
  nobull@mail.com wrote:
> troylachinski@my-deja.com writes:
>
> > I am converting a comma delimited file to a fixed length file.  At
the
> > end of each record I need to add a carriage return (HEX 0D
= "\x0d"?)
> > and then a line feed (HEX 0A = "\x0a"?).  When I add these the
record
> > gets an extra byte.

 ...skipped...

>
>   print NEW "$plu_number$plu_descriptor\x0d\x0a";
>

Hm-m, you really like these hex digits ;-)
AFAIK Perl (and C) has "\r" for CR and "\n" for LF.
Ilja.


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


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

Date: Mon, 8 May 2000 21:34:24 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: trouble with a conversion
Message-Id: <Pine.GHP.4.21.0005082130350.3709-100000@hpplus01.cern.ch>

On Mon, 8 May 2000, Ilja wrote:

> AFAIK Perl (and C) has "\r" for CR and "\n" for LF.

And perldoc perlport shows what's wrong with _that_.

An identity that only works on most of the platforms where Perl is
implemented, is no "identity" at all.  

(Admittedly, as the contents of CGI.pm reveal, one has to be quite
resourceful to write code that's portable not only on the Mac, but
also on EBCDIC-based platforms!).



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

Date: Mon, 08 May 2000 19:14:11 GMT
From: qazwart@my-deja.com
Subject: Using comma separators in decimal formatting in "printf"
Message-Id: <8f73li$ree$1@nnrp1.deja.com>

I have a number that I want to format with commas. I am using Active
Perl on NT (version 5.6.0). The following program:

    printf "%,10d\n", 12345678;
    printf "%10d\n", 12345678;

prints out:

    ,10d
      12345678

I want to print out:

    12,345,678

The second edition of the Camel book refers me to sprintf for
formatting functions, and sprintf says to refer to printf(3) which
states that you can use the "," as a flag at the beginning of your
format specification.

This wouldn't bother me so much, except I am pretty sure I did this
before.


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


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

Date: 8 May 2000 15:55:53 -0500
From: tzz@iglou.com (Teodor Zlatanov)
Subject: Re: Using comma separators in decimal formatting in "printf"
Message-Id: <39171bc9$1_1@news.iglou.com>

<8f73li$ree$1@nnrp1.deja.com>:qazwart@my-deja.com:comp.lang.perl.misc:Mon, 08 May 2000 19:14:11 GMT:quote:
: I have a number that I want to format with commas. 
: I want to print out:
: 
:     12,345,678

If you are posting from Deja News, maybe you could have
checked their archive for past postings on this topic?
This is a very frequently recurring topic, aka an FAQ.

perldoc -q comma
perldoc perlfaq5

       How can I output my numbers with commas added?

Just look in the HTML documentation for the perlfaq5 entry, if 
you don't use perldoc.  But you should.

-- 
Teodor Zlatanov <tzz@iglou.com>
"Brevis oratio penetrat colos, longa potatio evacuat ciphos." -Rabelais


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

Date: Mon, 8 May 2000 12:58:43 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Using comma separators in decimal formatting in "printf"
Message-Id: <MPG.1380bc4b55bb773298aa24@nntp.hpl.hp.com>

In article <8f73li$ree$1@nnrp1.deja.com> on Mon, 08 May 2000 19:14:11 
GMT, qazwart@my-deja.com <qazwart@my-deja.com> says...
> I have a number that I want to format with commas. I am using Active
> Perl on NT (version 5.6.0). The following program:
> 
>     printf "%,10d\n", 12345678;
>     printf "%10d\n", 12345678;
> 
> prints out:
> 
>     ,10d
>       12345678
> 
> I want to print out:
> 
>     12,345,678
> 
> The second edition of the Camel book refers me to sprintf for
> formatting functions, and sprintf says to refer to printf(3) which
> states that you can use the "," as a flag at the beginning of your
> format specification.

That must refer to some nonstandard C implementation of printf.  The 
Perl implementation has no such flag, as you could see by consulting its 
documentation (`perldoc -f sprintf`), which was inadequate when the 
Camel book was published.

> This wouldn't bother me so much, except I am pretty sure I did this
> before.

Using Perl?

perlfaq5: "How can I output my numbers with commas added?"

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


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

Date: Mon, 08 May 2000 20:33:10 GMT
From: Dick Latshaw <latsharj@my-deja.com>
Subject: Re: Using comma separators in decimal formatting in "printf"
Message-Id: <8f78a5$12v$1@nnrp1.deja.com>

In article <8f73li$ree$1@nnrp1.deja.com>,
  qazwart@my-deja.com wrote:
> I have a number that I want to format with commas.

Didn't check the FAQ's, did we?

>perldoc -q comma
Found in d:\Perl\lib\pod\perlfaq5.pod
  How can I output my numbers with commas added?
--
Regards,
Dick

--
Regards,
Dick


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


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

Date: Mon, 08 May 2000 21:13:21 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Using comma separators in decimal formatting in "printf"
Message-Id: <391829a6.1603974@news.skynet.be>

qazwart@my-deja.com wrote:

>I have a number that I want to format with commas. I am using Active
>Perl on NT (version 5.6.0). The following program:
>
>    printf "%,10d\n", 12345678;
>    printf "%10d\n", 12345678;
>
>prints out:
>
>    ,10d
>      12345678
>
>I want to print out:
>
>    12,345,678

The common name is "commify", but "perldoc -q commify" reveals nothing.
But "perldoc -q comma" turns up:

	Found in .../perlfaq5.pod
	  How can I output my numbers with commas added?

            This one will do it for you:

                sub commify {
                    local $_  = shift;
                    1 while s/^(-?\d+)(\d{3})/$1,$2/;
                    return $_;
                }

-- 
	Bart.


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

Date: Mon, 08 May 2000 20:40:02 +0200
From: Jens Rathmann <jrathmann@gmx.de>
Subject: Win32::ODBC / creating a new database file
Message-Id: <39170A02.9AF1763A@gmx.de>

Hi

I use Win32::ODBC in a Windows Perl-Script to access a database. I can
read, write and delete elements, but I cannot figure out how to create a
new database file that contains a single table, e.g. "Testtable", with
two fields "Field1" and "Field2". Important is, that the two field have
both string type and have a maximum length of 255 characters.

Anyone knows how to do it?

Thanks!

Jens




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

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


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