CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Post deleted by waldauf

 



waldauf
Novice

Aug 23, 2012, 1:43 AM

Post #1 of 7 (1272 views)
Post deleted by waldauf

 


Laurent_R
Veteran / Moderator

Aug 23, 2012, 1:58 AM

Post #2 of 7 (1271 views)
Re: [waldauf] Use subroutine instead die message [In reply to] Can't Post

You are not telling what your problem is.


waldauf
Novice

Aug 23, 2012, 2:54 AM

Post #3 of 7 (1268 views)
Re: [Laurent_R] Use subroutine instead die message [In reply to] Can't Post

Hello coll's,

I'm sorry I removed the original post of this topic so I created it here. I have problem with calling subroutine instead of "die message". I replaced "die message" by subroutine but this solution didn't work.


Perl code for reading input argument:

Code
sub BadInputParam_s { 
print <<EOF;
Input parameter: @_ is not allowed. For more information use help screen.

EOF
exit 1;
}


GetOptions ('channel=s' => \$channel, 'state=s' => \$state) or BadInputParam_s(@ARGV);
~


Output:

Code
$ ./remote_channel_ctrl.pl 
$



Perl code for reading input argument. Somewhere I read I have to call subroutine like scalar variable:


Code
sub BadInputParam_s { 
print <<EOF;
Input parameter: @_ is not allowed. For more information use help screen.

EOF
exit 1;
}

~
GetOptions ('channel=s' => \$channel, 'state=s' => \$state) or $BadInputParam_s(@ARGV);
~


Output

Code
$ ./remote_channel_ctrl.pl 
Variable "$help_s" is not imported at ./remote_channel_ctrl.pl line 104.
(Did you mean &help_s instead?)
Global symbol "$help_s" requires explicit package name at ./remote_channel_ctrl.pl line 104.
syntax error at ./remote_channel_ctrl.pl line 107, near "print"
Execution of ./remote_channel_ctrl.pl aborted due to compilation errors.



(This post was edited by waldauf on Aug 23, 2012, 6:10 AM)


rovf
Veteran

Aug 23, 2012, 5:43 AM

Post #4 of 7 (1263 views)
Re: [waldauf] Use subroutine instead die message [In reply to] Can't Post


Quote
Python code for reading input argument


Are you talking about Python or Perl?


waldauf
Novice

Aug 23, 2012, 5:58 AM

Post #5 of 7 (1258 views)
Re: [rovf] Use subroutine instead die message [In reply to] Can't Post

I was talking about Perl of course but I bad wrote Python (now it is fixed) :]. I found out solution which was very simply so I wanted to remove my topic but I removed only first post. I'll fix it.

I couldn't run subroutine instead of "die message" because I removed word "die". Now it is working fine.

My previous line:

Code
GetOptions ('channel=s' => \$channel, 'state=s' => \$state) or BadInputParam_s(@ARGV);


And the solution:

Code
GetOptions ('channel=s' => \$channel, 'state=s' => \$state) or die BadInputParam_s(@ARGV);





Now I have problem with handover variable/scalar to subroutine. Permit parameters are -s|--state and -c|--channel.

Code
sub BadInputParam_s { 
print <<EOF;
Input parameter: @_ is not allowed. For more information use help screen.

EOF
exit 1;
}


#GetOptions ('channel=s' => \$channel, 'state=s' => \$state, 'help' => \$help) or die "Uncorrect usege!\n";
GetOptions ('channel=s' => \$channel, 'state=s' => \$state, 'help' => \$help) or die BadInputParam_s(@ARGV);


Output:

Code
 ~ $ ./remote_channel_ctrl.pl -a 
Input parameter: is not allowed. For more information use help screen.



(This post was edited by waldauf on Aug 23, 2012, 6:11 AM)


FishMonger
Veteran / Moderator

Aug 23, 2012, 6:29 AM

Post #6 of 7 (1250 views)
Re: [waldauf] Use subroutine instead die message [In reply to] Can't Post

IMO, a better solution is to use Pod::Usage as documented in the Getopt::Long documentation.

http://search.cpan.org/~jv/Getopt-Long-2.38/lib/Getopt/Long.pm#Documentation_and_help_texts

http://search.cpan.org/~marekr/Pod-Parser-1.51/lib/Pod/Usage.pm


waldauf
Novice

Aug 23, 2012, 11:12 PM

Post #7 of 7 (1235 views)
Re: [FishMonger] Use subroutine instead die message [In reply to] Can't Post

Thx for your tip FishMonger but for my using is pod2usage() to complicate. I write simple perl script which learns me perl. But I saved it for my next usage ;].


wldf

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives