Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass a variable to subroutine

Status
Not open for further replies.
Jun 3, 2007
84
US
Hello,

I am having trouble getting the following to work. Here is what I am doing,
I have a sub that searches for logs files in a directory that always start and end with 08 and 00.

I then open each one of the files and look try to match another string using regex.

Once the second string is matched I save that string to a variable, split it on : and save the 2 part to an array.

Now using the contents in the second array (@spt1) I want to search for those files names in another directory. The problem is that the $spls variable when printed in the sub wanted does not print anything.

So my question is how do I use the contents of foreach $spls in the "sub wanted" subroutine?

Thanks for the help in advance! sample code.

Code:
sub search {
    if ( (-f) && /08\..*00$/ )
        open the file
        while ( $line  = <open log file> ) { 
            if ( $line =~ m/regex/ ) {
                @spt = split(/\:/, $line);
                push(@spt1,@spt[1]);
                foreach $spls (@spt1) {
                    find(&wanted, $seek_path, $spls);
                    sub wanted {
                        print $spls;
                   }
               }
           }
 
FYI forgot to leave out the following is I do the following then I can print out the correct output of $spls variable but when adding the find it breaks it. So how can I use file:find correctly.

Code:
sub search {
    if ( (-f) && /08\..*00$/ )
        open the file
        while ( $line  = <open log file> ) {
            if ( $line =~ m/regex/ ) {
                @spt = split(/\:/, $line);
                push(@spt1,@spt[1]);
                foreach $spls (@spt1) {
                    wanted($seek_path, $spls);#THIS LINE WORKS WHEN REMOVING FIND and adding SHIFT @_ below.
                    sub wanted {
                        my $spls = shift @_;
                        print $spls;
                   }
               }
           }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top