Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Getopt::Declare's demo_csv

by sg (Pilgrim)
on Feb 04, 2011 at 20:55 UTC ( [id://886298]=perlquestion: print w/replies, xml ) Need Help??

sg has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

Question: Why doesn't the script demos/demo_csv provided with Getopt::Declare behave as expected?

Here are some details:

The intent of the script is to have parameter specifications of the form:

<name:qs> , <id:+i> , <score:0+n> STD FORMAT [repeatable] { push @::students, {name=>$name, id=>$id, score=>$score} }
( there's a tab before the STD) which would match the test arguments in the script of the form:
absmith,1234567,20
The match should happen since white space in the specifications around the commas mean optional white space in the argument. However, the script does not achieve the intent -- the above argument does not match. Adding spaces between the commas in the argument does result in a match.

Question: why doesn't the match happen?

Thanks.

Replies are listed 'Best First'.
Re: Getopt::Declare's demo_csv
by toolic (Bishop) on Feb 05, 2011 at 17:13 UTC
    I downloaded Getopt::Declare and ran the script. Here is what I get:
    c:> perl demo_csv UNIVERSAL->import is deprecated and will be removed in a future perl a +t C:/Perl5-12-2/site/lib/Getopt/Declare.pm line 5 Unknown entry format: [absmith,1234567,20] Unknown entry format: ["aesmith, the other one",7635656,DNS] Unknown entry format: [cat,dog,22.2] Unknown entry format: [7637843,dejones,66.7] Unknown entry format: [rmwilliams,288721,88] Unknown entry format: [help me,I'm trapped,in the marks system] Unknown entry format: [vtthan,872829,94] c:> perl -v This is perl 5, version 12, subversion 2 (v5.12.2) built for MSWin32-x +86-multi-thread
    It is not clear to me what the script should do, but that output looks bad.
    • Show how you run the script.
    • Show the output you get.
    • Show the output you expect to get.
    I recommend that you reduce the code to the minimal amount and explain what you think it should do. I have no experience with the module, and the POD is quite long. Update: see also the module review.

      1) In demo.csv, modify the assignment to $data (by adding spaces around certain ',') to end up with:

      $data = q{ absmith , 1234567 , 20 "aesmith, the other one" ,7635656 , DNS cat , dog , 22.2 7637843 , dejones , 66.7 rmwilliams , 288721 , 88 help me,I'm trapped,in the marks system vtthan , 872829 , 94 };

      One then gets the output intended by the author of demo.csv (I am not he)

      Unknown entry format: [cat , dog , 22.2] Unknown entry format: [help me,I'm trapped,in the marks system] 1234567 (absmith): 20 7637843 (dejones): 66.7 288721 (rmwilliams): 88 872829 (vtthan): 94 7635656 ("aesmith, the other one"): ABSENT

      But according to the documentation of Getopt::Declare, the lack of spaces around the ',' shouldn't matter and original demo.csv should also give the above output.

        If you are convinced the module does behave as specified, you can file a bug report.

        Make sure you are using the latest version: Getopt-Declare-1.13

        If you're feeling ambitious, look at the source code to see if you can find where the problem is. You will increase the chances of the module being fixed if you can provide a patch.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://886298]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-19 20:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found