Find the answer to your Linux question:
Results 1 to 4 of 4
Code: package file_handler_funcs; sub legal($) { my $file_name = shift; $file_name =~ s/\s/\ /g; $file_name =~ s/\(/\(/g; $file_name =~ s/\)/\)/g; $file_name =~ s/'/\'/g; return ($file_name); } 1; Code: #!/usr/bin/perl use ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User
    Join Date
    Apr 2003
    Location
    TEXAS
    Posts
    314

    Am I missing something in this code


    Code:
    package file_handler_funcs;
    
    sub legal($) {
      my $file_name = shift;
      
      $file_name =~ s/\s/\\ /g;
      $file_name =~ s/\(/\\(/g;
      $file_name =~ s/\)/\\)/g;
      $file_name =~ s/'/\\'/g;
    
      return ($file_name);
    }
    
    1;
    Code:
    #!/usr/bin/perl
    
    use file_handler_funcs;
    
    @dirs = `ls -lR $ARGV[0]`;
    $sum = 0;
    foreach $dir (@dirs) {
      chomp($dir);
      if($dir =~ /^-/) {
        @info = split /\s+/,$dir,9;
        $sum+=$info[4];
        $file=legal($info[$#info]);
        print("$file\n");
      }
    }
    this gives me a compile error saying legal doesnt exist.[/code]
    The computer made me do it!! Slackware and SUSE too Gig\'em WHOOOOP!!
    \"God put me on this earth to accomplish a certain amount of tasks, At the rate I\'m going I will never die.\" (I don\'t know)

  2. #2
    Linux Engineer
    Join Date
    Jan 2003
    Location
    Lebanon, pa
    Posts
    994
    You must either add something like this to your module:
    Code:
    require Exporter;
    
    @ISA = qw(Exporter);
    @EXPORT = qw(legal);
    or call legal like this:
    Code:
    file_handler_funcs::legal

  3. #3
    Linux Engineer
    Join Date
    Jan 2003
    Location
    Lebanon, pa
    Posts
    994
    Oh yeah I forgot you call call it like this
    Code:
    file_handler_funcs->legal
    BTW you might want to add my $self =shift; in your subs in your module since it passes the package name to it first.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux User
    Join Date
    Apr 2003
    Location
    TEXAS
    Posts
    314
    thanx for the help
    The computer made me do it!! Slackware and SUSE too Gig\'em WHOOOOP!!
    \"God put me on this earth to accomplish a certain amount of tasks, At the rate I\'m going I will never die.\" (I don\'t know)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •