User Profile

Collapse

Profile Sidebar

Collapse
endure10
endure10
Last Activity: Nov 25 '11, 12:10 AM
Joined: Feb 19 '11
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Code:
    my @files = ($file1, $file2, $file3, $file4);
    foreach (@files) {
      open FILE, $_ or die "------ Could not open $_ testlist. \n"; 
      my @line = <FILE>;
      close FILE;
      &compare(\%var,\@line);
    }
    
    sub compare {
      my $var = shift;
      my @line = @_;
      foreach my $ln (@line) {
        if (exists $var->{$ln}) {
          $var->{$ln}++;
    ...
    See more | Go to post

    Leave a comment:


  • Sorry I was trying to delete that previous post because that warning is irrelevant to this problem but I didn't know how.

    Anyway, I did implement your method of passing the hash and array and also your variable naming convention. I checked to see if I could modify the values of the hash in the subroutine and everything checks out. However, my problem in your code equivalent would be at line 19 and is still the same as before
    ...
    See more | Go to post

    Leave a comment:


  • Thanks Miller.

    I am trying to implement the sample code for referencing and dereferencing but I run into the error of
    Code:
    Use of uninitialized value in hash element
    at line 5 of the code I posted. I initialize the hash in line 1 so I don't understand why my code would return this error.

    Once again, thank you for the help.
    See more | Go to post

    Leave a comment:


  • Hi,
    Well the conditional statement in line 20:
    if (exists($var{$l n}))
    is never successful and so, the values of the hashes are never incremented. So I was wondering if the syntax in lines 13 and 16-18 for passing the array and hash is correct, which I believe has nothing to do with the subroutine returning a value.
    See more | Go to post

    Leave a comment:


  • endure10
    started a topic How to pass an array and hash to a subroutine
    in Perl

    How to pass an array and hash to a subroutine

    Hi everyone,

    I'm working on a script that takes in a certain file A and compares it against several other files and prints any lines that exist in A but not in the other files. I was able to code a script so that File A is compared against 4 other files.

    However, to improve code readability and compare File A against a variable number of files, I am trying to make the actual comparison process a subroutine so that it...
    See more | Go to post
No activity results to display
Show More
Working...