Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Unable to untar

by raghubilhana (Initiate)
on Jun 27, 2007 at 01:52 UTC ( [id://623525]=perlquestion: print w/replies, xml ) Need Help??

raghubilhana has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I am having a problem untarring a tar file. I am very new to perl. Can you please help me . I am attaching the code here.

#!/usr/bin/perl use warnings; use FindBin; $distrib_dir = $FindBin::Bin; print "$distrib_dir"; sub RemoveWhiteSpaces; my ( ${birt_dir}, ${distrib_dir}, ${hostname} ); $birt_dir = "/usr/local/web/acc/WAS/install/61x/lib/app/birt"; $tar_dir="${distrib_dir}/../jclass/cfi_mss_srvcs/was6x-config"; print "$tar_dir"; $hostname=`uname -n`; $hostname = RemoveWhiteSpaces( ${hostname} ); if (! -d ${birt_dir} ) { die "The target directory /usr/local/web/acc/WAS/install/61x/li +b/app/birt does not exist, please create the directory as webspher an +d try again"; } if ( (${hostname} eq "agaisg66") || (${hostname} eq "svag0035") || (${ +hostname} eq "svag1103") ) { chdir "${birt_dir}"; print `pwd`; `cp -R "${distrib_dir}"/../jclass/cfi_mss_srvcs/BIRT/* .`; `tar xvf ${distrib_dir}/../jclass/cfi_mss_srvcs/was6x-config/lib- +app-CFI_Reporting.tar`; } else { print "You are trying to deploy the code in the wrong box"; ###################################################
I cant run this script and is giving the following messages:
Scalar value @_[0] better written as $_[0] at cfi_mss_srvcs_deploy.pl line 69.
Use of uninitialized value in concatenation (.) or string at cfi_mss_srvcs_deploy.pl line 39.

Can you please help me to untar the files. Your help will be really apprecited.

Replies are listed 'Best First'.
Re: Unable to untar
by graff (Chancellor) on Jun 27, 2007 at 02:42 UTC
    I took the trouble of using "view source" on my browser so that I could actually read the code snippet. If you are seriously looking for help, you have posted the wrong combination of code and perl diagnostic messages, because the messages you quote (Scalar value @_[0] better written as $_[0] and so on) have absolutely no relation at all to the code you originally posted.

    Since you are new to perl, please take a step or two back, and tell us what you are actually trying to do. You have a tar file? Is it compressed ("tar.gz")? Is there some reason you want to manipulate this file with a perl script, rather than just using the "tar" shell command?

    To untar a tar file, you would normally use the "tar" command, in one of the following ways:

    tar xf file_name.tar # or, if the tar file is compressed: tar xzf file_name.tar.gz
    What else do you need to know, and what's the point of all that perl code that you tried to post?
Re: Unable to untar
by jesuashok (Curate) on Jun 27, 2007 at 05:58 UTC

    #!/usr/bin/perl use warnings; use FindBin; $distrib_dir = $FindBin::Bin; print "$distrib_dir"; sub RemoveWhiteSpaces; my ( ${birt_dir}, ${distrib_dir}, ${hostname} ); $birt_dir = "/usr/local/web/acc/WAS/install/61x/lib/app/birt"; $tar_dir="${distrib_dir}/../jclass/cfi_mss_srvcs/was6x-config"; print "$tar_dir"; $hostname=`uname -n`; $hostname = RemoveWhiteSpaces( ${hostname} ); if (! -d ${birt_dir} ) { die "The target directory /usr/local/web/acc/WAS/install/61x/lib/a +pp/birt does not exist, please create the directory as webspher and t +ry again"; } if ( (${hostname} eq "agaisg66") || (${hostname} eq "svag0035") || ($ +{hostname} eq "svag1103") ) { chdir "${birt_dir}"; print `pwd`; `cp -R "${distrib_dir}"/../jclass/cfi_mss_srvcs/BIRT/* .`; `tar xvf ${distrib_dir}/../jclass/cfi_mss_srvcs/was6x-config/lib-a +pp-CFI_Reporting.tar`; } else { print "You are trying to deploy the code in the wrong box"; }
    In the above code which is actually given in the node, you are assigning a value to $distrib_dir = $FindBin::Bin; then you are declaring the saame variable as follows my ( ${birt_dir}, ${distrib_dir}, ${hostname} ); which will make the $distrib_dir as empty. Because I could see the you are using $distrib_dir in getting the value of $tar_dir.

      Hi Thanks for the reply. but the code $tar_dir="${distrib_dir}/../jclass/cfi_mss_srvcs/was6x-config"; does not work for some reason. Do you have any idea why?
Re: Unable to untar
by sago (Scribe) on Jun 27, 2007 at 11:41 UTC

    Try this.,

    If suppose there is a tar file by name "files_test.tar" in desktop and you want to untar them,see the below code..it worked fine for me.

    use Archive::Tar;
    chdir("C:/Documents and Settings/John_Kinn/Desktop");
    my $tar = Archive::Tar->new;
    $tar->read("files_test.tar", 1);
    my @files = $tar->list_files();
    print "I can see @files in th specified location.\n";
    $tar->extract(@files);
    print "The files are untared\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://623525]
Approved by ysth
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-25 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found