Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to debug perl script

Posted on 2007-12-06
5
Medium Priority
?
1,799 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 150 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Six Sigma Control Plans
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

916 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