Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Getopt::Long::GetOptions checking input array for file extensions

by toolic (Bishop)
on Aug 08, 2014 at 02:56 UTC ( [id://1096710]=note: print w/replies, xml ) Need Help??


in reply to Getopt::Long::GetOptions checking input array for file extensions

The reason @xls is empty is because you did not assign it any values. Typically, this is done by passing a variable reference to GetOptions for it to assign values to the variable (but using a sub might also accomplish this). It's not clear to me yet what you are trying to do. Please update your post with expected values for your variables.

UPDATE:

use strict; use warnings; use Getopt::Long(); sub usage { my $message = shift(@_); if ( defined $message && length $message ) { $message .= "\n" unless $message =~ /\n$/; } my $command = $0; $command =~ s#^.*/##; print STDERR ( $message, "usage: $command -f file(s).xls -p file.c +sv\n" ); die("\n"); } my @xls; my $csv; print "This is the number of \@ARGV arguments before the process " . @ +ARGV . "\n"; Getopt::Long::GetOptions( 'f=s' => \@xls, 'p=s' => \$csv, ) or usage("Invalid commmand line options."); usage("The '*.xls' file(s) needs to be specified.") if scalar( @xls == 0 ); usage("The '*.csv' file needs to be specified.") unless defined $csv; print "Input given form \@xls: " . @xls . "\n"; print "Input given form \$csv: " . $csv . "\n"; use Data::Dumper; print Dumper(\@xls); __END__ Here is my output: This is the number of @ARGV arguments before the process 6 Input given form @xls: 2 Input given form $csv: test.csv $VAR1 = [ 'sample.xls', 'test.xls' ];
  • Comment on Re: Getopt::Long::GetOptions checking input array for file extensions
  • Download Code

Replies are listed 'Best First'.
Re^2: Getopt::Long::GetOptions checking input array for file extensions
by thanos1983 (Parson) on Aug 08, 2014 at 10:56 UTC

    Hello toolic,

    Thank you for your time and effort to assist me with my problem. I have updated the code and also the explanation to my problem. Apologies if it was not so clear from the beginning.

    Seeking for Perl wisdom...on the process...not there...yet!

Log In?
Username:
Password:

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

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

    No recent polls found