Sponsored Content
Full Discussion: Need help If empty - perl
Top Forums Shell Programming and Scripting Need help If empty - perl Post 302557041 by birei on Tuesday 20th of September 2011 10:31:06 AM
Old 09-20-2011
The $file variable is out of scope when you check it. It doesn't exists when the foreach loop ends. Try using an additional array variable.

Code:
$ #!/usr/bin/perl -w
print "Enter Advance Search Function: ";
chomp ($func = <STDIN>);
my @func1 = split(' ', $func);
while ($func ne "quit")
{
    if (($func1[0] eq "/") && ($func1[2] eq "/"))
    {
                my @files = glob $func1[1];
                if ( ! @files ) {
                        print "there no file that you looking for. please Re-Enter\n";
                }
                else {
                        foreach my $file ( @files ) {
                                print $file, "\n";
                        }
                }


#      foreach $file (glob "$func1[1]") 
#      {
#          #if ($file) 
#          # {
#              print "$file\n";
#          # }
#      }
#        if ($file == 0 )
#        {
#          print "there no file that you looking for. please Re-Enter\n";
#         }
        
    }
    else
        {
            print " Incorrect vaiable was entered\n";
        }
    
print "Enter Advance Search Function: ";
chomp ($func = <STDIN>);

}

And I suppose you will have to reasign user input to the variable @func1 inside the loop, because instead results will always be the same and incorrect.

Regards,
Birei
This User Gave Thanks to birei For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

printing an empty line in a file (perl)

I know this must be really easy, but i can't get it to work I've got a perl script, with a file. I want to print an empty line, and the following doesn't seem to work: print nameoffile "\n" thanks for your help!! (3 Replies)
Discussion started by: kfad
3 Replies

2. UNIX for Dummies Questions & Answers

how to find empty folders without using -empty

hi all: my solaris FIND does not support find myFolder -type d -empty how can i find the empty folders? thanks! (7 Replies)
Discussion started by: lasse
7 Replies

3. UNIX for Dummies Questions & Answers

How to check for empty file in Perl?

Hi, May I know how to check for empty file in Perl. Iam missing something, somewhere. #!/usr/bin/perl my $open_dir = '/path/'; my $file; my $ma = "abc_.*.\.psv\$" opendir(VAR, $open_dir) or die "Can't open $oepn_dir: $!\n"; while( defined ($file = readdir VAR) ) #read all... (1 Reply)
Discussion started by: deepakwins
1 Replies

4. UNIX for Dummies Questions & Answers

Getting same exit status for empty and non empty file

Hi All, I am checking for a empty input file to do some further action , but I am getting exit status 0 in both the cases , for empty and non empty file both. The value of $? is coming 0 in if part also and else part too. #!/bin/ksh if ]; then echo "data" # exit 0 echo "$?" else... (4 Replies)
Discussion started by: mavesum
4 Replies

5. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

6. Shell Programming and Scripting

perl or awk remove empty lines when condition

Hi Everyone, # cat 1 a b b cc 1 2 3 3 3 4 55 5 a b (2 Replies)
Discussion started by: jimmy_y
2 Replies

7. Shell Programming and Scripting

Perl : how to match non-empty string that has no spaces

Hi Everyone, I am looking for neat way to grep a non-empty string that basically contains a hostname, which might be in FWDN form or without the domain, for example: hostname.internal.domainname.net The file I am parsing contains blan lines (^$) and also series of "-" which in other places... (2 Replies)
Discussion started by: togr
2 Replies

8. Shell Programming and Scripting

Check if Queue empty or full in perl

Hi, I got problem with queue code how to determined empty and full and problem with while loop Here is my pseudo code : Input page Access Input Pgae Frame For i =3 to pageframe count by 1 construct queue of size i set pageFaultCount to 0 while morepages do page = NextPage... (1 Reply)
Discussion started by: guidely
1 Replies

9. Programming

Perl - How to empty a directory?

Hi Guys, i'm writing a perl script which whenever runs, should empty 3 pre-decided directories as first step and then the script has the logic to parse some other directories and copy the files inside those directories into these 3 directories. I've the logic already developed, just need to... (2 Replies)
Discussion started by: jhamaks
2 Replies

10. Shell Programming and Scripting

Perl , uploading empty file.

Hi The below script used to work fine. Suddenly it's uploading empty file. I am very new to perl. Please help me to find out the problem. #!/usr/bin/perl #script: upload.pl use CGI qw/:standard/; print header, start_html('File upload'); print_form(); print_results() if... (2 Replies)
Discussion started by: Anupam_Halder
2 Replies
autouse(3perl)						 Perl Programmers Reference Guide					    autouse(3perl)

NAME
autouse - postpone load of modules until a function is used SYNOPSIS
use autouse 'Carp' => qw(carp croak); carp "this carp was predeclared and autoused "; DESCRIPTION
If the module "Module" is already loaded, then the declaration use autouse 'Module' => qw(func1 func2($;$)); is equivalent to use Module qw(func1 func2); if "Module" defines func2() with prototype "($;$)", and func1() has no prototypes. (At least if "Module" uses "Exporter"'s "import", otherwise it is a fatal error.) If the module "Module" is not loaded yet, then the above declaration declares functions func1() and func2() in the current package. When these functions are called, they load the package "Module" if needed, and substitute themselves with the correct definitions. WARNING
Using "autouse" will move important steps of your program's execution from compile time to runtime. This can o Break the execution of your program if the module you "autouse"d has some initialization which it expects to be done early. o hide bugs in your code since important checks (like correctness of prototypes) is moved from compile time to runtime. In particular, if the prototype you specified on "autouse" line is wrong, you will not find it out until the corresponding function is executed. This will be very unfortunate for functions which are not always called (note that for such functions "autouse"ing gives biggest win, for a workaround see below). To alleviate the second problem (partially) it is advised to write your scripts like this: use Module; use autouse Module => qw(carp($) croak(&$)); carp "this carp was predeclared and autoused "; The first line ensures that the errors in your argument specification are found early. When you ship your application you should comment out the first line, since it makes the second one useless. AUTHOR
Ilya Zakharevich (ilya@math.ohio-state.edu) SEE ALSO
perl(1). perl v5.14.2 2011-09-19 autouse(3perl)
All times are GMT -4. The time now is 06:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy