?
Solved

how to debug perl script

Posted on 2007-12-06
5
Medium Priority
?
1,785 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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…

719 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