Solved

how to debug perl script

Posted on 2007-12-06
5
1,742 Views
Last Modified: 2010-04-21
hi guys,
i have to perl script which has shell script extention like
script name is deploy.sh
#!/usr/local/bin/perl -w
# $Id: deploy.sh 1214 2007-04-04 19:45:36Z  $
# Testing


how to debug this script...i gave set -x but didn't work..
i don't understand this if you can explain me
 my ($product, $version) =  $filename =~  m!^(\w+)-(.+)-SNAPSHOT(?:.+) $!mxi or die "Here $filename";
0
Comment
Question by:parlepoint
  • 2
  • 2
5 Comments
 
LVL 39

Expert Comment

by:Adam314
ID: 20421407
For general debugging, there is a perl debugger:
http://perldoc.perl.org/perldebug.html

In the statement you have above:
This part:
    my ($product, $version)
declares two variables, $product and $version.  It it not normally required to declare variables before use, but is generally considered good practice to add a "use strict" statement, which requires variable declaration.

This part:
    $filename =~ m!^(\w+)-(.+)-SNAPSHOT(?:.+) $!
Matches the variable $filename against a regular expression.  A regular expression is used for searching for patterns in strings.  See these pages for more on regular expressions:
    http://perldoc.perl.org/perlrequick.html
    http://perldoc.perl.org/perlretut.html
You can use this to get a description of a regular expression:
    print YAPE::Regex::Explain->new(qr!^(\w+)-(.+)-SNAPSHOT(?:.+) $!)->explain;
    in this case:
  ^                        the beginning of the string
----------------------------------------------------------------------
  (                        group and capture to \1:
----------------------------------------------------------------------
    \w+                      word characters (a-z, A-Z, 0-9, _) (1 or
                             more times (matching the most amount
                             possible))
----------------------------------------------------------------------
  )                        end of \1
----------------------------------------------------------------------
  -                        '-'
----------------------------------------------------------------------
  (                        group and capture to \2:
----------------------------------------------------------------------
    .+                       any character except \n (1 or more times
                             (matching the most amount possible))
----------------------------------------------------------------------
  )                        end of \2
----------------------------------------------------------------------
  -SNAPSHOT                '-SNAPSHOT'
----------------------------------------------------------------------
  (?:                      group, but do not capture:
----------------------------------------------------------------------
    .+                       any character except \n (1 or more times
                             (matching the most amount possible))
----------------------------------------------------------------------
  )                        end of grouping
----------------------------------------------------------------------
                           ' '
----------------------------------------------------------------------
  $                        before an optional \n, and the end of the
                           string
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------

This part:
    or die "Here $filename";
causes your program to die (exit with an error code and message) if the variable $filename doesn't match the pattern.
0
 

Author Comment

by:parlepoint
ID: 20421748
thanks adam, problem with script has extension .sh if there is perl then i can do with -w option.
there is not any option in docs link which you send it to me.

if you have any idea about debug deploy.sh which has all perl language.
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 50 total points
ID: 20421891
If the file is a perl program, from the prompt:
    perl -w deploy.sh

Perl does not care what the extension of the file is.  Windows uses the extension to determine the type of a file, and what program to use for that file.  Unix does not the extension for anything.
0
 
LVL 1

Expert Comment

by:ajay_kanse
ID: 20424568
U can use perl -d <filename> ....This will give you a debugger prompt . You can stepin the programme by line . Hope that helps.
0
 

Author Closing Comment

by:parlepoint
ID: 31413187
Thanks Adam
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now