[28390] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9754 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 22 14:06:06 2006

Date: Fri, 22 Sep 2006 11:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 22 Sep 2006     Volume: 10 Number: 9754

Today's topics:
        Convert file to excel <pradeep.bg@gmail.com>
        differences between hashes and arrays ? <jack_posemsky@yahoo.com>
    Re: differences between hashes and arrays ? <peace.is.our.profession@gmx.de>
    Re: differences between hashes and arrays ? <mritty@gmail.com>
    Re: differences between hashes and arrays ? <bik.mido@tiscalinet.it>
    Re: differences between hashes and arrays ? <tadmc@augustmail.com>
    Re: differences between hashes and arrays ? <bik.mido@tiscalinet.it>
    Re: differences between hashes and arrays ? <syscjm@gwu.edu>
    Re: differences between hashes and arrays ? xhoster@gmail.com
    Re: differences between hashes and arrays ? <jack_posemsky@yahoo.com>
    Re: differences between hashes and arrays ? <mritty@gmail.com>
    Re: differences between hashes and arrays ? <nobull67@gmail.com>
    Re: explaining how memory works with tie()ed hashs <botfood@yahoo.com>
    Re: Help with plotting <bik.mido@tiscalinet.it>
        How identify if more than one option is specified? <shah@typhoon.xnet.com>
    Re: How identify if more than one option is specified? <mritty@gmail.com>
    Re: How identify if more than one option is specified? <David.Squire@no.spam.from.here.au>
    Re: How identify if more than one option is specified? <john@castleamber.com>
    Re: Repeated captures from the same pattern and string <brandon.n.atkinson@gmail.com>
    Re: Russel Quong's "Perl in 20 pages" <1usa@llenroc.ude.invalid>
    Re: sort with Perl .. <1usa@llenroc.ude.invalid>
    Re: where to put dclone <graham.removethis.t.wood@andthis.oracle.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 22 Sep 2006 10:49:22 -0700
From: "Deepu" <pradeep.bg@gmail.com>
Subject: Convert file to excel
Message-Id: <1158947362.371084.163390@b28g2000cwb.googlegroups.com>

Hi All,

I am trying to create a table with some data and store it in a file and
then it should be used in excel to create 3D bar chart. Can some one
provide me with some ideas on how it can be done.

Thanks for your time.

Code:

I have file which contains so many other details and have a line in the

file which start with:

#RESULT: 30 => YES: 10 NO: 10 UNKNOWN: 10

I have several files with each file have a line with RESULT.

##### Code starts here ####

#!/usr/bin/perl

@dirList= qw(FILE1 FILE2 FILE3 FILE4 FILE5);

foreach $dir (@dirList) {
   open (PH, "$dir") || die "Can not open:$dir";

   while (<PH>) {
      if (/#RESULT: (\d+) => YES: (\d+) NO: (\d+) UNKNOWN: (\d+)/) {
         push (@yesArray, $2);
         push (@noArray, $3);
         push (@unknownArray, $4);
      }
   }

close (PH);

}

## -- help from Mumia W ---
my $fmt = "-%10s   %5s   %5s    %5s\n";
printf ($fmt, '', qw(YES  NO  UNKNOWN));

foreach $dir(@dirList) {
   printf $fmt, $dir, $yesArray[$_], $noArray[$_], $unknownArray[$_];
   $_++;
}

The output generated is:

            YES        NO       UNKNOWN
FILE1       10           8               14
FILE2        6            7               20
FILE3        18          10             10
FILE4        20          12             10
FILE5        10          10             10

Now i am trying to save this table in a file so that it can be read by
Excel and create bar chart. Is there any way possible to automate this
flow.

Thanks for the help.



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

Date: 22 Sep 2006 07:55:56 -0700
From: "Jack" <jack_posemsky@yahoo.com>
Subject: differences between hashes and arrays ?
Message-Id: <1158936955.959183.305650@m73g2000cwd.googlegroups.com>

Hi folks I am not an expert in perl but correct me if I am wrong -

is it true you can use a hash and work with it just as you would an
array - what are the differences between them (besides in an array you
can have a multidimensional array) ?

why arent folks using hashes instead of arrays since (I believe) they
are faster to access and take up the same or less memory than arrays..

Thanks,

Jack



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

Date: Fri, 22 Sep 2006 17:16:47 +0200
From: Mirco Wahab <peace.is.our.profession@gmx.de>
Subject: Re: differences between hashes and arrays ?
Message-Id: <ef0v16$2cr$1@mlucom4.urz.uni-halle.de>

Thus spoke Jack (on 2006-09-22 16:55):

> is it true you can use a hash and work with it just as you would an
> array - what are the differences between them (besides in an array you
> can have a multidimensional array) ?

There is a similar interface, but thats almost all.

==> http://en.wikipedia.org/wiki/Hash_table

In short, a 'hash table' is a complicated organism
which allows you to find an item (say: key, stored
in there) in very very short time, which is the point.

An "array" means otherwise "access by an index number",
so array elements must be searched in order to
find a particular item.

compare:

    my $item = $hash{ 'ITEM_OF_INTEREST' }; # gets the item

vs.

   SEARCH: foreach $element (@array) {
      if($element eq 'ITEM_OF_INTEREST') {
         $item = $element;                  # gets the item
         last SEARCH;
      }
   }

> why arent folks using hashes instead of arrays since (I believe) they
> are faster to access and take up the same or less memory than arrays..

No, folks using hashes if hash tables are appropriate
and arrays if arrays are ...

Say, you have ten million 3D coordinate points
which are in some order already (an order that
means something to you). Why would you bother to
put them in a hash table, if all you need is sub-
sequent access to the 13244'st or 10'th to 1923331'th?

Regards

Mirco


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

Date: 22 Sep 2006 08:35:01 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: differences between hashes and arrays ?
Message-Id: <1158939301.199293.224230@i3g2000cwc.googlegroups.com>

Jack wrote:
> Hi folks I am not an expert in perl but correct me if I am wrong -

You're wrong. :-)

> is it true you can use a hash and work with it just as you would an
> array

No.

> - what are the differences between them

A hash is by definition unordered.  There is no ordering of any kind to
the key/value pairs in a hash.  An array is ordered - there is a very
well defined sequence of which item follows which item.  Therefore, you
can treat an array like a stack or a queue (using the push/pop
shift/unshift set of functions), while this is not possible with a
hash.  With a hash you can associate to distinct pieces of data in one
structure, and can retrieve a specific value in very efficient time.

An array is indexed by positive integers.  A hash is keyed by any
string, whether its contents are numeric or not.

> (besides in an array you
> can have a multidimensional array) ?

Ironically, that is *not* one of the differences.  You can have
multidimensional hashes as well.  In fact, you can have hashes of
arrays, arrays of hashes, arrays of hashes of hashes, hashes of arrays
of hashes, or any other combination you'd like.

> why arent folks using hashes instead of arrays since (I believe) they
> are faster to access and take up the same or less memory than arrays..

Faster to access, yes.  Same or less memory, no.

These are not apples to apples.  You use a hash and an array for
completely different purposes.

If you have an example of a program or algorithm you're working on, we
could help you get rid of some of your misperceptions. . . .

Paul Lalli



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

Date: 22 Sep 2006 17:39:39 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: differences between hashes and arrays ?
Message-Id: <et08h2d8crh5jq2nqkomqgthtr5l8etkb3@4ax.com>

On Fri, 22 Sep 2006 17:16:47 +0200, Mirco Wahab
<peace.is.our.profession@gmx.de> wrote:

>==> http://en.wikipedia.org/wiki/Hash_table
>
>In short, a 'hash table' is a complicated organism
>which allows you to find an item (say: key, stored
>in there) in very very short time, which is the point.

But that is an "implementation detail", albeit one of fundamental
importance to the very nature of the actual thing...


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Fri, 22 Sep 2006 10:34:05 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: differences between hashes and arrays ?
Message-Id: <slrneh80jd.o3j.tadmc@magna.augustmail.com>

Jack <jack_posemsky@yahoo.com> wrote:

> is it true you can use a hash and work with it just as you would an
> array - 


No.


> what are the differences between them 


Arrays are ordered and indexed with numbers.

Hashes are UNordered and indexed with strings.


> (besides in an array you
> can have a multidimensional array) ?


You can also have a multidimensional hash, so that is not
one of the differences.


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


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

Date: 22 Sep 2006 17:53:38 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: differences between hashes and arrays ?
Message-Id: <7v08h2p982c60apgh609o4eq8uci1o7m25@4ax.com>

On 22 Sep 2006 07:55:56 -0700, "Jack" <jack_posemsky@yahoo.com> wrote:

>Hi folks I am not an expert in perl but correct me if I am wrong -

Seeing your question and your considerations below, indeed you seem
not to be an expert in perl. So I guess you're not wrong.

>is it true you can use a hash and work with it just as you would an
>array - what are the differences between them (besides in an array you
>can have a multidimensional array) ?

You can also have multidimensional hashes. But both are not "real"
multidimentional beasts. However for the moment don't bother...

Really hashes are associative arrays, i.e. they are a finite mapping
between a set of _keys_ and a set _values_. The keys are generic
strings. An array is a mapping between a finite set of natural numbers
of the form {0,... , n} (if you don't set $[ to something other than
0, but again, don't bother!) and a set of values.

>why arent folks using hashes instead of arrays since (I believe) they
>are faster to access and take up the same or less memory than arrays..

You will certainly know that in perl conversions between numbers and
strings happen automagically all the time. So indeed you may use a
hash to implement an array. However hashes are called like that
because their implementation is based on hash tables that provide
means to quickly search through the keys. There's no particular
general advantage when the keys are simple numbers instead.

So use an array when you need a mapping from a finite set of numbers
to some values, except possibly when the mapping is very sparse. How
much is "very", may depend on many factors, and I don't know the lower
limit exactly. Surely I would use a hash if I need to *explicitly* set
the mapping amongst say 100 numbers uniformely distribuited in
0..100_000_000 and some values. I don't have the vaguest idea how well
the hashing algorithm would hash such keys, but the thing can be
investigated...


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Fri, 22 Sep 2006 12:32:27 -0400
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: differences between hashes and arrays ?
Message-Id: <12h840sagl7ckd2@corp.supernews.com>

Jack wrote:
> Hi folks I am not an expert in perl but correct me if I am wrong -
> 
> is it true you can use a hash and work with it just as you would an
> array -

No, because arrays are ordered and hashes are not.

> what are the differences between them (besides in an array you
> can have a multidimensional array) ?

A "multidimensional array" in Perl is simply an array of arrays.
You can have hashes of hashes as well--or a hash of arrays, or
an array of hashes, or whatever meets your needs.

> 
> why arent folks using hashes instead of arrays since (I believe) they
> are faster to access and take up the same or less memory than arrays..
> 

Um, no, arrays are much more efficient than hashes.


-- 
              Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: 22 Sep 2006 16:37:34 GMT
From: xhoster@gmail.com
Subject: Re: differences between hashes and arrays ?
Message-Id: <20060922123910.446$Xa@newsreader.com>

"Jack" <jack_posemsky@yahoo.com> wrote:
> Hi folks I am not an expert in perl but correct me if I am wrong -
>
> is it true you can use a hash and work with it just as you would an
> array

That would depend on what you are doing.  For some things, you could easily
use them interchangably.  For most things, you can't.  If youre indices are
not integers, you can't use arrays.  When your indices are integers but are
not densely packed but need to accessed as though they were, you cannot
readily use hashes.


> - what are the differences between them (besides in an array you
> can have a multidimensional array) ?

That is not a difference between them (in Perl).

> why arent folks using hashes instead of arrays since (I believe) they
> are faster to access and take up the same or less memory than arrays..

Wrong on both counts.  When arrays and hashes are interchangable, hashes
are much slower and take substantially more memory.


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 22 Sep 2006 10:01:50 -0700
From: "Jack" <jack_posemsky@yahoo.com>
Subject: Re: differences between hashes and arrays ?
Message-Id: <1158944510.294811.199680@m73g2000cwd.googlegroups.com>


Michele Dondi wrote:
> On 22 Sep 2006 07:55:56 -0700, "Jack" <jack_posemsky@yahoo.com> wrote:
>
> >Hi folks I am not an expert in perl but correct me if I am wrong -
>
> Seeing your question and your considerations below, indeed you seem
> not to be an expert in perl. So I guess you're not wrong.
>
> >is it true you can use a hash and work with it just as you would an
> >array - what are the differences between them (besides in an array you
> >can have a multidimensional array) ?
>
> You can also have multidimensional hashes. But both are not "real"
> multidimentional beasts. However for the moment don't bother...
>
> Really hashes are associative arrays, i.e. they are a finite mapping
> between a set of _keys_ and a set _values_. The keys are generic
> strings. An array is a mapping between a finite set of natural numbers
> of the form {0,... , n} (if you don't set $[ to something other than
> 0, but again, don't bother!) and a set of values.
>
> >why arent folks using hashes instead of arrays since (I believe) they
> >are faster to access and take up the same or less memory than arrays..
>
> You will certainly know that in perl conversions between numbers and
> strings happen automagically all the time. So indeed you may use a
> hash to implement an array. However hashes are called like that
> because their implementation is based on hash tables that provide
> means to quickly search through the keys. There's no particular
> general advantage when the keys are simple numbers instead.
>
> So use an array when you need a mapping from a finite set of numbers
> to some values, except possibly when the mapping is very sparse. How
> much is "very", may depend on many factors, and I don't know the lower
> limit exactly. Surely I would use a hash if I need to *explicitly* set
> the mapping amongst say 100 numbers uniformely distribuited in
> 0..100_000_000 and some values. I don't have the vaguest idea how well
> the hashing algorithm would hash such keys, but the thing can be
> investigated...
>
>
> Michele
> --
> {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
> (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
> .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
> 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

Thanks for the comments all.   For these applications, which is better
suited, array or hash, and assume a very large volume of data and
consider memory :
1- iterate through a huge list (hash or array?) of values and compare
each value in the list, 1 by 1, to a match condition test like
m/^\d.*?\d$/  (all digits), and then keep the count of the values that
pass the match test
2- compare all values in column 1, file 1 (one value at a time ; assume
10M records ) to determine if the value exists in the target list (hash
or array?) from column 2 file 2 (assume column 2 is 20M records)

Thank you,
Jack



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

Date: 22 Sep 2006 10:21:58 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: differences between hashes and arrays ?
Message-Id: <1158945718.098301.10710@m7g2000cwm.googlegroups.com>

Jack wrote:
> Thanks for the comments all.   For these applications, which is better
> suited, array or hash, and assume a very large volume of data and
> consider memory :
> 1- iterate through a huge list (hash or array?) of values and compare
> each value in the list, 1 by 1, to a match condition test like
> m/^\d.*?\d$/  (all digits), and then keep the count of the values that
> pass the match test

array.  You just want to iterate over all of them, in sequence.  No
reason for the overhead of a hash.

my $count = grep /^\d.*?\d$/ @great_big_array;

(by the way, you do know that your pattern does not match "all digits",
right?  It matches anything that starts with and ends with a digit, of
at least length two.  The "inside" of the value can be literally
anything.)

> 2- compare all values in column 1, file 1 (one value at a time ; assume
> 10M records ) to determine if the value exists in the target list (hash
> or array?) from column 2 file 2 (assume column 2 is 20M records)

column1, file1 - array.  You want to iterate over all of them, one at a
time, in sequence.

column2, file2 - hash.  You want to access a specific element of your
set, without knowing or caring where in the set that element falls.

for my $value (@column1){
   if (exists $column2{$value}) {
     print "$value exists in column2 file2\n";
   } else {
     print "$vlaue does not exist in column2 file2\n";
   }
}

Paul Lalli



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

Date: 22 Sep 2006 10:38:13 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: differences between hashes and arrays ?
Message-Id: <1158946693.148097.24030@h48g2000cwc.googlegroups.com>


xhoster@gmail.com wrote:
> "Jack" <jack_posemsky@yahoo.com> wrote:
> > why arent folks using hashes instead of arrays since (I believe) they
> > are faster to access and take up the same or less memory than arrays..
>
> Wrong on both counts.  When arrays and hashes are interchangable, hashes
> are much slower and take substantially more memory.

Except in the rare and special case of a very sparsely populated array.



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

Date: 22 Sep 2006 10:24:05 -0700
From: "botfood" <botfood@yahoo.com>
Subject: Re: explaining how memory works with tie()ed hashs
Message-Id: <1158945844.847352.227820@e3g2000cwe.googlegroups.com>


Jim Gibson wrote:
> > ----------------
> > the machine running the script is a webserver on a remote host... they
> > dont give access to any place I can watch memory.
>
> That makes it tough. However, you can do yourself a favor by setting up
> a local Perl installation and running your tests on it. My guess is
> that the regular expression engine doesn't vary very much from platform
> to platform.
> --------------------------------

however, Berkley DB and memory management is probably different between
win32 and Linux, so it wouldnt give me any more than a rough ballpark.
My test server at home is not Apache, I use Xitami, so I cant really
emulate the SizeLimit stuff that was a problem on the web server......
kinda shooting in the dark.

best guess at this point is that s// on a string that is 20k 'words' of
20 characters, *probably* eats up more memory that the host server
wants to allocate for any single process.

d



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

Date: 22 Sep 2006 17:34:43 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Help with plotting
Message-Id: <17s7h29h4vadado7jepbqb0s45g81cqc1t@4ax.com>

On Thu, 21 Sep 2006 21:26:19 GMT, "Mumia W. (reading news)"
<paduille.4058.mumia.w@earthlink.net> wrote:

>I'm lucky to be using Debian. Debian Linux is probably the biggest 
>collection of free software in existence, and PDL::Graphics::PLplot is 
>included in Debian as part of Debian's "pdl" package.

OTOH they're sometimes too picky for my tastes. While developing
something on a debian box I had been needing a module which relied on
a certain package. I had a hard time trying to install and put the
module to work until I realized it wanted a -devel part of the package
too.

On a more general level, endless discussions tend to arise as to
whether it is better to install packages with CPAN.pm or with one's
distro tools. A relatively unknown fact is that CPANPLUS buys one the
best of both worlds building distro-specific packages on the fly.
Unfortunately supported target distros are not yet that many. As time
permits I'd like to investigate if it's easy to write a front-end for
the "minor" distro I'm using: all in all it should be, due to the
relatively lightweight package system it uses.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Fri, 22 Sep 2006 17:27:10 +0000 (UTC)
From: Hemant Shah <shah@typhoon.xnet.com>
Subject: How identify if more than one option is specified?
Message-Id: <ef16de$non$1@new7.xnet.com>


Folks,

  Is there a easy way to find out if more than one option is specified.

  Example:

  use Getopt::Std;
  getopts(abc);
  if ($opt_a || $opt_b || $opt_c) {}

  I only want user to specify one of the options (either -a or -b -or -c). 
  How do I easily check if they have specified more than one option.

  I can write "if" statement as follows:

  if (($opt_a && $opt_b && $opt_c) ||
       ($opt_a && $opt_b) ||
       ($opt_b && $opt_c) ||
       ($opt_a && $opt_c))
  {
     # print error message.
  }

  This could get ugly if the number of possible options is greater than 3.

  Is there an easier way?

  Thanks.

-- 
Hemant Shah                           /"\  ASCII ribbon campaign
E-mail: NoJunkMailshah@xnet.com       \ /  --------------------- 
                                       X     against HTML mail
TO REPLY, REMOVE NoJunkMail           / \      and postings      
FROM MY E-MAIL ADDRESS.           
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind,                Above opinions are mine only.
it's backed up on tape somewhere.      Others can have their own.


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

Date: 22 Sep 2006 10:34:20 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: How identify if more than one option is specified?
Message-Id: <1158946460.743652.76810@b28g2000cwb.googlegroups.com>

Hemant Shah wrote:
> Folks,
>
>   Is there a easy way to find out if more than one option is specified.
>
>   Example:
>
>   use Getopt::Std;
>   getopts(abc);
>   if ($opt_a || $opt_b || $opt_c) {}
>
>   I only want user to specify one of the options (either -a or -b -or -c).
>   How do I easily check if they have specified more than one option.
>
>   I can write "if" statement as follows:
>
>   if (($opt_a && $opt_b && $opt_c) ||
>        ($opt_a && $opt_b) ||
>        ($opt_b && $opt_c) ||
>        ($opt_a && $opt_c))
>   {
>      # print error message.
>   }
>
>   This could get ugly if the number of possible options is greater than 3.
>
>   Is there an easier way?

This isn't significantly prettier, but...

if (grep { defined } ($opt_a, $opt_b, $opt_c) > 1) {
  # print error message
}

Paul Lalli



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

Date: Fri, 22 Sep 2006 18:40:33 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: How identify if more than one option is specified?
Message-Id: <ef175e$nks$1@gemini.csx.cam.ac.uk>

Hemant Shah wrote:
> Folks,
> 
>   Is there a easy way to find out if more than one option is specified.
> 
>   Example:
> 
>   use Getopt::Std;
>   getopts(abc);
>   if ($opt_a || $opt_b || $opt_c) {}
> 
>   I only want user to specify one of the options (either -a or -b -or -c). 
>   How do I easily check if they have specified more than one option.

If there should only ever be one, why not change your approach? Allow 
only one option, but let it be one that takes an argument, and let that 
argument select between the behaviours you are currently specifying via 
-a XOR -b XOR -c.


DS


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

Date: 22 Sep 2006 17:58:05 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: How identify if more than one option is specified?
Message-Id: <Xns984683E9CD3AEcastleamber@130.133.1.4>

Hemant Shah <shah@typhoon.xnet.com> wrote:

> 
> Folks,
> 
>   Is there a easy way to find out if more than one option is
>   specified. 
> 
>   Example:
> 
>   use Getopt::Std;
>   getopts(abc);
>   if ($opt_a || $opt_b || $opt_c) {}
> 
>   I only want user to specify one of the options (either -a or -b -or
>   -c). How do I easily check if they have specified more than one
>   option.

my $option = shift;
$option eq '-a' or $option eq '-b' or $option eq '-c'
    	or die "usage: script -a|-b|-c";

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

Date: 22 Sep 2006 08:23:28 -0700
From: "gorjusborg" <brandon.n.atkinson@gmail.com>
Subject: Re: Repeated captures from the same pattern and string
Message-Id: <1158938608.661192.115200@e3g2000cwe.googlegroups.com>

Mirco Wahab wrote:
> Thus spoke gorjusborg (on 2006-09-21 22:26):
>
> > while ($text =~ m{$pattern1($pattern2)$pattern3\(}msg) {
> >     push @instance, "$1";
> > }
> > ...
> > The problem is, though I'm getting the _number_ of matches I'd expect
> > (verified visually), I'm only getting the captured text from the first
> > match in $1, but repeated the number of times the pattern matches in
> > the text...  What gives??
>
>
> The code posted seems so far ok, which means your
> error is somewhere else. As David pointed out,
> please post some code that allows us to
> replicate your problem.
>
> I did run your (slightly modified, see "$1")
> code against some random Nietzsche paragraph
> in order to find out all non capitalized
> words between two capitalized ones - and
> your code indeed did work:
>
>   ...
>   $text = do { local $/; <DATA> };  # pull some Nietzsche stuff ;-)
>
>   $pattern1 = '\b[A-Z][a-z]+\s+';
>   $pattern2 = '[a-z]+';
>   $pattern3 = '\s+[A-Z][a-z]+';
>
>   while( $text =~ m{$pattern1($pattern2)$pattern3}gms ) {
>      push @instance, $1;
>   }
>   print join "\n", @instance;
>   ...
>
>  __DATA__
>  (put your favorite quote here)
>
>
> Regards
>
> Mirco

Thanks for the patience and heads-up on posting manners, as may be
obvious, I'm new to posting on useNet.

Mirco,
Thanks for help.
I'll look into it further, and post if the results are interesting.

=gorj=



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

Date: Fri, 22 Sep 2006 12:41:24 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Russel Quong's "Perl in 20 pages"
Message-Id: <Xns9846586D91F4Dasu1cornelledu@127.0.0.1>

John Bokma <john@castleamber.com> wrote in
news:Xns9845B72FC7338castleamber@130.133.1.4: 

> I will review 
> <http://visibooks.com/pdfs/TheVisibooksGuidetoPERLBasics50.pdf>
> 
>                                               ^^^^ Yes, the title says
>                                                    it all.
> 
> next week when I am hopefully recovered of the first glance at this
> book excerpt.

That thing is pure genius. Ohmigoooood! There is so little Perl in the 
excerpt it is hard to say anything detailed, but the HTML they show is all 
messed up, they get the CGI content type header wrong, and they can't even 
figure out why variables exist in programming languages.

The newspaper published Basic tutorial that first got me so excited about 
computers in 1981 now looks like a computer science classic compared to 
this thing.

*Aaaaaaaargh!*

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: Fri, 22 Sep 2006 12:32:55 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: sort with Perl ..
Message-Id: <Xns984656FD8DCBCasu1cornelledu@127.0.0.1>

"Mumia W. (reading news)" <paduille.4058.mumia.w@earthlink.net> wrote in
news:BNyQg.14545$bM.5257@newsread4.news.pas.earthlink.net: 

> On 09/21/2006 09:19 AM, David Squire wrote:
>> Mumia W. (reading news) wrote:
>>> [ snipped ]
>> 
>> What happened to waiting for the OP to at least make an attempt? If
>> we're just doing folks work for them today, here's a moduleless
>> version: [...]
> 
> Yes, I should've waited for the OP's version of the program. I was
> just excited about find out about Sort::Fields :-)

I have been fairly busy lately, and by the time I am able to read the 
group, all questions have been answered adequately. But, this thread 
really rubbed me the wrong way.

Mumia:

Please choose a posting address and stick with it. I don't want to have 
to re-plonk you every couple of months.

Yours is exactly the kind of behavior that keeps people coming back for 
'gimme's.

Since Taher's only other response in this thread did not show that he 
paid attention to anyone other than the one who gave him the fish, I 
won't be seeing his future messages either.


Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Fri, 22 Sep 2006 13:54:50 +0100
From: Graham Wood <graham.removethis.t.wood@andthis.oracle.com>
Subject: Re: where to put dclone
Message-Id: <WlRQg.41$V4.167@news.oracle.com>

Thanks to all for the responses.  I've added some parentheses around

my(@found, @missing);

And it seems to be working the way I want it now.  I'll file away the 
map trick for future reference.

Graham



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

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


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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

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

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


------------------------------
End of Perl-Users Digest V10 Issue 9754
***************************************


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