LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   perl tar ext cheack (https://www.linuxquestions.org/questions/linux-newbie-8/perl-tar-ext-cheack-702245/)

knockout_artist 02-04-2009 09:29 AM

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

theNbomr 02-04-2009 10:44 AM

To use regex testing, you need the '=~' notation:
Code:

  if( $name =~ m/$tar/ ){
      print $name;
  }

--- rod.

knockout_artist 02-04-2009 12:58 PM

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

theNbomr 02-04-2009 01:14 PM

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.

knockout_artist 02-04-2009 02:34 PM

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.

chrism01 02-04-2009 05:53 PM

To get a 'not match' in Perl use

$name !~ /pattern/

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


All times are GMT -5. The time now is 01:55 AM.