[28059] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9423 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 4 14:05:54 2006

Date: Tue, 4 Jul 2006 11:05:04 -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           Tue, 4 Jul 2006     Volume: 10 Number: 9423

Today's topics:
        about ssh remote <Deb.Fang@gmail.com>
    Re: about ssh remote <noreply@gunnar.cc>
        ANN: Spreadsheet::Read 0.16 <h.m.brand@xs4all.nl>
    Re: ANN: Spreadsheet::Read 0.16 <h.m.brand@xs4all.nl>
    Re: Crimson Editor query <sherm@Sherm-Pendleys-Computer.local>
    Re: languages with full unicode support <pjb@informatimago.com>
    Re: languages with full unicode support <mumia.w.18.spam+nospam.usenet@earthlink.net>
    Re: languages with full unicode support <David.Squire@no.spam.from.here.au>
    Re: languages with full unicode support <pjb@informatimago.com>
    Re: scope trouble <sherm@Sherm-Pendleys-Computer.local>
        Searching a string in a list of delimited fields <ronaldf@eml.cc>
    Re: Searching a string in a list of delimited fields <mritty@gmail.com>
    Re: Searching a string in a list of delimited fields <simon.chao@gmail.com>
    Re: Searching a string in a list of delimited fields <rvtol+news@isolution.nl>
    Re: Searching a string in a list of delimited fields <mumia.w.18.spam+nospam.usenet@earthlink.net>
    Re: Searching a string in a list of delimited fields <DJStunks@gmail.com>
        Treasure Trooper curtisdulmadge@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 4 Jul 2006 09:30:53 -0700
From: "debbie523" <Deb.Fang@gmail.com>
Subject: about ssh remote
Message-Id: <1152030652.245201.250680@j8g2000cwa.googlegroups.com>

I have a cgi script named test12.cgi
There is a line

$output=`ssh -l userName serverName  echo hello`;
print $output;

(username is my account name, serverName is the server name)

test12.cgi is my action for try.php file. When I test this line through
browser, $output is nothing.

But if I execute test12.cgi in command window, it does print "hello"

Is there somebody could tell me why it does not show anything from the
browser?



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

Date: Tue, 04 Jul 2006 18:46:56 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: about ssh remote
Message-Id: <4gvk87F1p6pboU1@individual.net>

debbie523 wrote:
> I have a cgi script named test12.cgi
> There is a line
> 
> $output=`ssh -l userName serverName  echo hello`;
> print $output;
> 
> (username is my account name, serverName is the server name)
> 
> test12.cgi is my action for try.php file. When I test this line through
> browser, $output is nothing.
> 
> But if I execute test12.cgi in command window, it does print "hello"
> 
> Is there somebody could tell me why it does not show anything from the
> browser?

The command failed?

Please read the docs about the backticks operator in "perldoc perlop" 
for examples on how a command's STDERR can be captured.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Tue, 4 Jul 2006 11:01:37 GMT
From: "H.Merijn Brand" <h.m.brand@xs4all.nl>
Subject: ANN: Spreadsheet::Read 0.16
Message-Id: <J1vqG6.s11@zorch.sf-bay.org>

The URL

     http://www.xs4all.nl/~hmbrand/Spreadsheet-Read-0.16.tgz

has entered CPAN as

   file: $CPAN/authors/id/H/HM/HMBRAND/Spreadsheet-Read-0.16.tgz
   size: 42789 bytes
    md5: 87f9a96182b71d195bc6b1fede03b495

This is a quickened release for Jim Ford, as he reads his spreadsheets
with Perl and Spreadsheet::Read, and wanted color support. Enjoy!

NAME
        Spreadsheet::Read $,1x2(B Read the data from a spreadsheet

SYNOPSYS
         use Spreadsheet::Read;
         my $ref = ReadData ("test.csv", sep => ";");
         my $ref = ReadData ("test.sxc");
         my $ref = ReadData ("test.ods");
         my $ref = ReadData ("test.xls");

         my $a3 = $ref$,1rp(B>[1]{A3}, "\n"; # content of field A3 of sheet 1

DESCRIPTION
        Spreadsheet::Read tries to transparantly read *any* spreadsheet and
        return its content in a universal manner independent of the parsing
        module that does the actual spreadsheet scanning.

0.16    Tue 04 Jul 2006

     - xlscat new option: --in-sep-char to force-define input sep-char for  CSV
     - More debug lines
     - Parser name info in $ref->[0]
     - SquirrelCalc now reports Spreadsheet::Read and its version for  parser
info
     - Most of the attributes for Excel now implemented. Tested, but no  test
case

0.15    Wed 21 Jun 2006

     - Small doc change from AnnoCPAN
     - Sheets with undefined labels might cause havoc
     - Clip now skips empty xls sheets (TODO: sxc)
     - xlscat clips by default
     - xlscat new options -d and --noclip
     - xlscat usage () from -?/--help to STDOUT from fault to STDERR

0.14    Fri 20 Jan 2006

     - maxrow and maxcol were swapped in csv sheets
     - promoted internal debug flag to option
     - small doc changes




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

Date: Tue, 4 Jul 2006 13:36:48 GMT
From: "H.Merijn Brand" <h.m.brand@xs4all.nl>
Subject: Re: ANN: Spreadsheet::Read 0.16
Message-Id: <J1vt2p.v6A@zorch.sf-bay.org>

On Tue, 04 Jul 2006 13:01:37 +0200, H.Merijn Brand <h.m.brand@xs4all.nl>
wrote:

> The URL
>
>      http://www.xs4all.nl/~hmbrand/Spreadsheet-Read-0.16.tgz

	http://www.xs4all.nl/~hmbrand/Spreadsheet-Read-0.17.tgz

0.17    Tue 04 Jul 2006

     - xlscat new option: --ansii to (try to) use the ansi colors for fields
     - Fixed a color attribute off-by-one error
     - Added test cases (not yet complete)
     - Added bold and underline

0.16 has been removed and/or marked for deletion

If installing from a color-enabled xterm, try

# xlscat -A -L files/attr.xls

after installation to see what 0.17 can do :)

> has entered CPAN as
>
>    file: $CPAN/authors/id/H/HM/HMBRAND/Spreadsheet-Read-0.16.tgz
>    size: 42789 bytes
>     md5: 87f9a96182b71d195bc6b1fede03b495
>
> This is a quickened release for Jim Ford, as he reads his spreadsheets
> with Perl and Spreadsheet::Read, and wanted color support. Enjoy!
>
> NAME
>         Spreadsheet::Read $,1x2(B Read the data from a spreadsheet
>
> SYNOPSYS
>          use Spreadsheet::Read;
>          my $ref = ReadData ("test.csv", sep => ";");
>          my $ref = ReadData ("test.sxc");
>          my $ref = ReadData ("test.ods");
>          my $ref = ReadData ("test.xls");
>
>          my $a3 = $ref$,1rp(B>[1]{A3}, "\n"; # content of field A3 of
> sheet 1
>
> DESCRIPTION
>         Spreadsheet::Read tries to transparantly read *any* spreadsheet  and
>         return its content in a universal manner independent of the  parsing
>         module that does the actual spreadsheet scanning.
>
> 0.16    Tue 04 Jul 2006
>
>      - xlscat new option: --in-sep-char to force-define input sep-char  for
> CSV
>      - More debug lines
>      - Parser name info in $ref->[0]
>      - SquirrelCalc now reports Spreadsheet::Read and its version for
> parser
> info
>      - Most of the attributes for Excel now implemented. Tested, but no
> test
> case
>
> 0.15    Wed 21 Jun 2006
>
>      - Small doc change from AnnoCPAN
>      - Sheets with undefined labels might cause havoc
>      - Clip now skips empty xls sheets (TODO: sxc)
>      - xlscat clips by default
>      - xlscat new options -d and --noclip
>      - xlscat usage () from -?/--help to STDOUT from fault to STDERR
>
> 0.14    Fri 20 Jan 2006
>
>      - maxrow and maxcol were swapped in csv sheets
>      - promoted internal debug flag to option
>      - small doc changes
>
>




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

Date: Tue, 04 Jul 2006 13:10:42 -0400
From: Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>
Subject: Re: Crimson Editor query
Message-Id: <m2psglthwt.fsf@Sherm-Pendleys-Computer.local>

"V S Rawat" <VSRawat@Invalid.none> writes:

> Any method of making Crimson Editor accept input from me?

Do you get the same results from scripts written in Python, Ruby, etc.?

If so, you have a Crimson Editor question, not a Perl question, and you'll
need to ask in whatever forum is appropriate for that.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Tue, 04 Jul 2006 12:19:45 +0200
From: Pascal Bourguignon <pjb@informatimago.com>
Subject: Re: languages with full unicode support
Message-Id: <873bdhvfi6.fsf@thalassa.informatimago.com>

Joachim Durchholz <jo@durchholz.org> writes:

> Oliver Bandel schrieb:
>> Matthias Blume wrote:
>> 
>>> Tin Gherdanarra <tinman31337@gmail.com> writes:
>>>
>>>
>>>> Oliver Bandel wrote:
>>>>
>>>>> こんいちわ Xah-Lee san ;-)
>>>>
>>>> Uhm, I'd guess that Xah is Chinese. Be careful
>>>> with such things in real life; Koreans might
>>>> beat you up for this. Stay alive!
>>>
>>>
>>> And the Japanese might beat him up, too.  For butchering their
>>> language. :-)
>> OK, back to ISO-8859-1 :)  no one needs so much symbols,
>> this is enough: äöüÄÖÜß :)
>
> If you want äöüÄÖÜß, anybody else will want their local characters,
> too, and nothing below full Unicode will work.
>
> Just for laughs, here's a list of non-ASCII Latin-based letters in
> Unicode (not verified for completeness):
>   ÀÁÂÃÄÅÆàáâãäåæĀāĂ㥹ǺǻǼǽ
>   ÇçĆćĈĉĊċČč
>   ĎďĐđ
>   ÈÉÊËèéêëĒēĔĕĖėĘęĚě
>   ĜĝĞğĠġĢģ
>   ĤĥĦħ
>   ÌÍÎÏìíîïĨĩĪīĬĭĮįİıIJij
>   Ĵĵ
>   Ķķĸ
>   ĹĺĻļĽĿŀŁł
>   Ðð
>   ÑñŃńŅņŇňʼnŊŋ
>   ÒÓÔÕØòóôöõŌōŎŏÖŐőŒœǾǿ
>   ŔŕŖŗŘř
>   ŚśŜŝŞşŠšß
>   ŢţŤťŦŧ
>   ÜÙÚÛüùúûŨũŪūŭŮůŰűŲų
>   Ŵŵ
>   ÝýÿŶŷŸ
>   Þþ
>   ŹźŻżŽž
>   ƒſ
> ISO 8859-1 covers just a fraction of these, so Unicode would indeed be
> necessary to allow a program written in one country to compile in
> another one.

Indeed, far from complete:

(coerce (lschar :name "LATIN") 'string)
--> "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
     ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóô
     õöøùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩ
     ĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝ
     ŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐƑ
     ƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDž
     džLJLjljNJNjnjǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴǵǶǷǸǹ
     ǺǻǼǽǾǿȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏȐȑȒȓȔȕȖȗȘșȚțȜȝȞȟȠȢȣȤȥȦȧȨȩȪȫȬȭȮ
     ȯȰȱȲȳɐɑɒɓɔɕɖɗɘəɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾ
     ɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭͣͤͥͦͧ
     ͨͩͪͫͬͭͮͯḀḁḂḃḄḅḆḇḈḉḊḋḌḍḎḏḐḑḒḓḔḕḖḗḘḙḚḛḜḝḞḟḠḡḢḣḤḥḦḧḨḩḪḫ
     ḬḭḮḯḰḱḲḳḴḵḶḷḸḹḺḻḼḽḾḿṀṁṂṃṄṅṆṇṈṉṊṋṌṍṎṏṐṑṒṓṔṕṖṗṘṙṚṛṜṝṞṟ
     ṠṡṢṣṤṥṦṧṨṩṪṫṬṭṮṯṰṱṲṳṴṵṶṷṸṹṺṻṼṽṾṿẀẁẂẃẄẅẆẇẈẉẊẋẌẍẎẏẐẑẒẓ
     ẔẕẖẗẘẙẚẛẠạẢảẤấẦầẨẩẪẫẬậẮắẰằẲẳẴẵẶặẸẹẺẻẼẽẾếỀềỂểỄễỆệỈỉỊị
     ỌọỎỏỐốỒồỔổỖỗỘộỚớỜờỞởỠỡỢợỤụỦủỨứỪừỬửỮữỰựỲỳỴỵỶỷỸỹⁱⁿ⒜⒝⒞⒟
     ⒠⒡⒢⒣⒤⒥⒦⒧⒨⒩⒪⒫⒬⒭⒮⒯⒰⒱⒲⒳⒴⒵ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⓐⓑⓒⓓ
     ⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ✝✞✟fffiflffifflſtstABCDEFGHIJ
     KLMNOPQRSTUVWXYZabcdefghij
     klmnopqrstuvwxyz"


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

READ THIS BEFORE OPENING PACKAGE: According to certain suggested
versions of the Grand Unified Theory, the primary particles
constituting this product may decay to nothingness within the next
four hundred million years.


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

Date: Tue, 04 Jul 2006 13:49:18 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: languages with full unicode support
Message-Id: <yluqg.2825$cd3.1769@newsread3.news.pas.earthlink.net>

Pascal Bourguignon wrote:
> [...]
> (coerce (lschar :name "LATIN") 'string)
> --> "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
>      
 > [...]

In what programming language/interpreter is this code?



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

Date: Tue, 04 Jul 2006 14:55:32 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: languages with full unicode support
Message-Id: <e8ds0g$lsv$1@gemini.csx.cam.ac.uk>

Mumia W. wrote:
> Pascal Bourguignon wrote:
>> [...]
>> (coerce (lschar :name "LATIN") 'string)
>> --> "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
>>      
>  > [...]
> 
> In what programming language/interpreter is this code?
> 

Looks pretty lispy to me... and comp.lang.lisp was in the original 
newsgroups list.


DS


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

Date: Tue, 04 Jul 2006 18:05:46 +0200
From: Pascal Bourguignon <pjb@informatimago.com>
Subject: Re: languages with full unicode support
Message-Id: <87ac7ptkx1.fsf@thalassa.informatimago.com>

"Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net> writes:

> Pascal Bourguignon wrote:
>> [...]
>> (coerce (lschar :name "LATIN") 'string)
>> --> "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
>>      
>> [...]
>
> In what programming language/interpreter is this code?

Common Lisp; in particular, clisp:

(defun string-match-p (pattern string)
  "Matches a string."
  #+(and clisp regexp) (regexp:match pattern string :ignore-case t)
  #-(and clisp regexp) (search       pattern string
                                     :test (function equalp)))

(defun lschar (&key (start 0) (end #x11000) name)
  "Prints all the characters of codes betwen start and end, with their names."
  (if name
      (loop :for code :from start :below end
         :when (string-match-p name (char-name (code-char code)))
         :collect #1=(progn (format t "#x~5,'0X  ~:*~6D  ~C  ~S~%"
                                    code (code-char code)
                                    (char-name (code-char code)))
                            (code-char code)))
      (loop :for code :from start :below end :collect #1#)))

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

This is a signature virus.  Add me to your signature and help me to live.


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

Date: Tue, 04 Jul 2006 13:16:01 -0400
From: Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>
Subject: Re: scope trouble
Message-Id: <m2lkr9thny.fsf@Sherm-Pendleys-Computer.local>

Dave Weaver <zen13097@zen.co.uk> writes:

> Sherm Pendley <sherm@Sherm-Pendleys-Computer.local> wrote:
>>  Shane <shane@weasel.is-a-geek.net> writes:
>> 
>> 
>> > for ($counter=0;$counter <=8;$counter++){ 
>> >     if (defined $puzzle->{$element}[$counter]){$element_counter++}
> ..................................................^..................^
>
>> > }
>> 
>>  There's no opening bracket on that if(). The other errors are likely to be the
>>  result of failed error recovery after the first error.
>
> Yes there is. But the horrible code layout obscured it.

Oops, you're right. Sorry for the noise.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Tue, 04 Jul 2006 12:59:04 +0200
From: Ronald Fischer <ronaldf@eml.cc>
Subject: Searching a string in a list of delimited fields
Message-Id: <1152010744.65@user.newsoffice.de>

I do already have a solution for my problem, but it looks
clumsy to me, so I would like to know if someone could
point out a more elegant way to do it (no need to post
"tested" code - just given general hints would be OK as
well).

PROBLEM: A string contains fields delimited by vertical bars
(optionally surrounded by spaces). The first and last
characters are guaranteed to be neither | nor a space. Example:

  my $s = "foo |   bar baz  | whoosh";

is assumed to denote 3 fields, "foo", "bar baz", and "whoosh".

Now giving a key,

  my $key = "bar baz";

return the number of the field (counting starts at 0) which equals
the key (here, it should return 1), or -1 if the field is not
present.

I implemented this in a pretty forward (aka: dull) way:

    my $index_found=-1;
    my @fields = split /\s*\|\s*/,$s;
    my $ind=0; # loops through fields
    FIELDNAMES: foreach my $x (@fields)
    {
        if($x eq $fieldname)
        {
          $index_found=$ind;
          last FIELDNAMES;
        }
        ++$ind;
      }
    }

Of course I could use a counted loop through the array instead
of a foreach, but I wouldn't see this as a real improvement.
I was thinking whether there would be a solution which does not
need an explicit loop at all, just employing regexp (maybe
with code blocks). Of course the resulting solution should not
be so obscure as to become unmaintainable.

Any suggestions?

Ronald

-- 
Ronald Fischer <ronaldf@eml.cc>
Posted via http://www.nesoffice.de/



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

Date: 4 Jul 2006 04:28:04 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Searching a string in a list of delimited fields
Message-Id: <1152012484.653904.209210@m73g2000cwd.googlegroups.com>

Ronald Fischer wrote:
> PROBLEM: A string contains fields delimited by vertical bars
> (optionally surrounded by spaces). The first and last
> characters are guaranteed to be neither | nor a space. Example:
>
>   my $s = "foo |   bar baz  | whoosh";
>
> is assumed to denote 3 fields, "foo", "bar baz", and "whoosh".
>
> Now giving a key,
>
>   my $key = "bar baz";
>
> return the number of the field (counting starts at 0) which equals
> the key (here, it should return 1), or -1 if the field is not
> present.
>
> I implemented this in a pretty forward (aka: dull) way:
>
>     my $index_found=-1;
>     my @fields = split /\s*\|\s*/,$s;
>     my $ind=0; # loops through fields
>     FIELDNAMES: foreach my $x (@fields)
>     {
>         if($x eq $fieldname)
>         {
>           $index_found=$ind;
>           last FIELDNAMES;
>         }
>         ++$ind;
>       }
>     }
>
> Of course I could use a counted loop through the array instead
> of a foreach, but I wouldn't see this as a real improvement.
> I was thinking whether there would be a solution which does not
> need an explicit loop at all, just employing regexp (maybe
> with code blocks). Of course the resulting solution should not
> be so obscure as to become unmaintainable.
>
> Any suggestions?

Hrm.  I can't off hand think of any way that involves just a regexp,
but my initial suggestion would be a hash populated by a call to map.
Then just check for the existance of the searched for value in the
hash:

#!/usr/bin/env perl
use strict;
use warnings;

sub find_idx {
  my ($fields, $find) = @_;
  my $i = 0;

  my %index_of = map { $_ => $i++ } split /\s*\|\s*/, $fields;

  return exists $index_of{$find} ? $index_of{$find} : -1;
}

my $index = find_idx('foo |   bar baz  | whoosh', 'bar baz');

print "Found: $index\n";
__END__

Hope this helps,
Paul Lalli



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

Date: 4 Jul 2006 05:16:19 -0700
From: "it_says_BALLS_on_your_forehead" <simon.chao@gmail.com>
Subject: Re: Searching a string in a list of delimited fields
Message-Id: <1152015378.913694.34180@m79g2000cwm.googlegroups.com>


Ronald Fischer wrote:
> I do already have a solution for my problem, but it looks
> clumsy to me, so I would like to know if someone could
> point out a more elegant way to do it (no need to post
> "tested" code - just given general hints would be OK as
> well).
>
> PROBLEM: A string contains fields delimited by vertical bars
> (optionally surrounded by spaces). The first and last
> characters are guaranteed to be neither | nor a space. Example:
>
>   my $s = "foo |   bar baz  | whoosh";
>
> is assumed to denote 3 fields, "foo", "bar baz", and "whoosh".
>
> Now giving a key,
>
>   my $key = "bar baz";
>
> return the number of the field (counting starts at 0) which equals
> the key (here, it should return 1), or -1 if the field is not
> present.
>
> I implemented this in a pretty forward (aka: dull) way:
>
>     my $index_found=-1;
>     my @fields = split /\s*\|\s*/,$s;
>     my $ind=0; # loops through fields
>     FIELDNAMES: foreach my $x (@fields)
>     {
>         if($x eq $fieldname)
>         {
>           $index_found=$ind;
>           last FIELDNAMES;
>         }
>         ++$ind;
>       }
>     }
>
> Of course I could use a counted loop through the array instead
> of a foreach, but I wouldn't see this as a real improvement.
> I was thinking whether there would be a solution which does not
> need an explicit loop at all, just employing regexp (maybe
> with code blocks). Of course the resulting solution should not
> be so obscure as to become unmaintainable.

List::MoreUtils::first_index()



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

Date: Tue, 4 Jul 2006 15:17:35 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Searching a string in a list of delimited fields
Message-Id: <e8e10t.1d8.1@news.isolution.nl>

Ronald Fischer schreef:

> A string contains fields delimited by vertical bars
> (optionally surrounded by spaces). The first and last
> characters are guaranteed to be neither | nor a space.

The first and last characters of what? The line? Each field?

> Any suggestions?

echo 'foo |   bar baz  | whoosh' | perl -nle '
  $, = "\n";
  print split / *\| */
'

foo
bar baz
whoosh

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: Tue, 04 Jul 2006 13:49:20 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: Searching a string in a list of delimited fields
Message-Id: <Aluqg.2826$cd3.2665@newsread3.news.pas.earthlink.net>

Ronald Fischer wrote:
> [...]
>  my $s = "foo |   bar baz  | whoosh";
> 
> is assumed to denote 3 fields, "foo", "bar baz", and "whoosh".
> 
> Now giving a key,
> 
>  my $key = "bar baz";
> 
> return the number of the field (counting starts at 0) which equals
> the key (here, it should return 1), or -1 if the field is not
> present.
> [...]
> 
> Any suggestions?
> 
> Ronald
> 

Sure:

use Data::Dumper;
use strict;

my $s = "foo |   bar baz  | whoosh";
my @fields = split /\s*\|\s*/, $s;
my %fields;
$fields{$fields[$_]} = $_ for (0..$#fields);

print Dumper(\%fields), "\n";

__END__

Now %fields is a hash that maps field names to field numbers.


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

Date: 4 Jul 2006 09:42:15 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Searching a string in a list of delimited fields
Message-Id: <1152031335.458587.92650@v61g2000cwv.googlegroups.com>


it_says_BALLS_on_your_forehead wrote:
> Ronald Fischer wrote:
> > I do already have a solution for my problem, but it looks
> > clumsy to me, so I would like to know if someone could
> > point out a more elegant way to do it (no need to post
> > "tested" code - just given general hints would be OK as
> > well).
> >
> > PROBLEM: A string contains fields delimited by vertical bars
> > (optionally surrounded by spaces). The first and last
> > characters are guaranteed to be neither | nor a space. Example:
> >
> >   my $s = "foo |   bar baz  | whoosh";
> >
> > is assumed to denote 3 fields, "foo", "bar baz", and "whoosh".
> >
> > Now giving a key,
> >
> >   my $key = "bar baz";
> >
> > return the number of the field (counting starts at 0) which equals
> > the key (here, it should return 1), or -1 if the field is not
> > present.
> >
> > I implemented this in a pretty forward (aka: dull) way:
> List::MoreUtils::first_index()

absolutely right.

  C:\>perl -MList::MoreUtils=firstidx -e "\
        print firstidx { $_ eq $ARGV[0] } \
        split /\s*\|\s*/, 'foo |   bar baz  | whoosh'" \
        foo
  0

  C:\>perl -MList::MoreUtils=firstidx -e "\
        print firstidx { $_ eq $ARGV[0] } \
        split /\s*\|\s*/, 'foo |   bar baz  | whoosh'" \
        "don't find me"
  -1

  C:\>perl -MList::MoreUtils=firstidx -e "\
        print firstidx { $_ eq $ARGV[0] } \
        split /\s*\|\s*/, 'foo |   bar baz  | whoosh'" \
        "whoosh"
  2

-jp



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

Date: 4 Jul 2006 09:51:05 -0700
From: curtisdulmadge@gmail.com
Subject: Treasure Trooper
Message-Id: <1152031865.760111.65280@l70g2000cwa.googlegroups.com>

 what you do here is you complete simple surveys and offers, some
require a credit card, but i just do all the free ones :D

its easy to do, you just register and do the offers, then click the
"done" button when you have completed it to what the instructions say,
here is the website if you want to check it out

www.treasuretrooper.com/111524 (copy and paste into browser

this is how the payment works: say in june you made 60$, then on the
15th of next month, so on july 15th you would get your money. they send
a check in the mail so yes, you have to provide your correct address,
not a fake one (dont worry they dont spam you with shit) and you will
get a check in the mail from them and you can cash it like any other
check.

so far, i have been doing this thing for 2 months and i have been payed
$156.50 total. its easy money and only takes about half an hour a day
if your really keen on it, but usually 10 minutes is fine. on their
forums i ha ve heard that people are making like $200+ i hope i can get
that much in the future. im pretty close.

once again, if you are interested in signing up, here is where you go:
www.treasuretrooper.com/111524  (copy and paste into your browser)



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

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


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