Solved

how to debug perl script

Posted on 2007-12-06
5
1,765 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…

739 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