LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-04-2009, 10:29 AM   #1
knockout_artist
Member
 
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324

Rep: Reputation: 33
perl tar ext cheack


Hi,


I tried doing some thing like this.

Code:
$tar= ".*\.tar";
$name= "file";



##  at test point

if ($name eq  $tar)
{
print $name;
}
But apparently it doesn't use regular expression as
I wanted.
Is there any other way to test if the file is tar?

Thanks
 
Old 02-04-2009, 11:44 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
To use regex testing, you need the '=~' notation:
Code:
   if( $name =~ m/$tar/ ){
      print $name;
   }
--- rod.
 
Old 02-04-2009, 01:58 PM   #3
knockout_artist
Member
 
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324

Original Poster
Rep: Reputation: 33
Thanks so much!

Actually what I needed was not equal to.

but when i do
Code:
 if( $name !=~ m/$tar/ )
again it doesnt work.

Sorry.

And thanks for your help
 
Old 02-04-2009, 02:14 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Perhaps you should explain in some detail what you mean by "doesn't work". What are you trying to accomplish? What are you seeing? Your posted code is only an incomplete fragment; does the complete script compile with errors or warnings?
--- rod.
 
Old 02-04-2009, 03:34 PM   #5
knockout_artist
Member
 
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324

Original Poster
Rep: Reputation: 33
I am sorry again I was too busy to update.

I used it as

Code:
if ($name  =~ m/$tar/){

next;
}else{
if (-M $name >  $days )  ## if file is over 4 days old


{
#print "$name\n";            # used for debug

system("$cmd $name.tar $name");   # zip file
 if(-e "$name.tar"  ){

# print "deleting $name.tar because $name.tar \n";
 system("$rm $name");            #remve the file after its zippped 
 }

I worked as i wanted thank you so much.

Last edited by knockout_artist; 02-04-2009 at 03:35 PM.
 
Old 02-04-2009, 06:53 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
To get a 'not match' in Perl use

$name !~ /pattern/

http://perldoc.perl.org/perlrequick.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl script using tar matt1982 Programming 16 02-13-2012 06:35 AM
How to make a tar file using perl prakash.akumalla Linux - Newbie 5 10-29-2008 08:18 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 03:53 AM
controling ext. devices with perl DanTaylor Programming 1 01-30-2006 02:20 PM
Filesystems: ext 2, ext 3, reiserfs. Which one? r3dhatter Linux - Newbie 12 07-15-2004 01:53 AM


All times are GMT -5. The time now is 02:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration