Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hey There! I'm quite a newbie with Perl and i'm stuck with subroutines and arrays.
#!/usr/bin/perl use strict; use warnings; use Getopt::Std; my $cimzett; my $domain; my $date; my @data; getopts ('m:d:s:'); use vars qw ($opt_m $opt_d $opt_s); $date=$opt_d; $domain=$opt_s; sub csv { open(BEJOVO, ">>bejovo.csv"); open(KIMENO, ">>kimeno.csv"); while (my $in = @data) { my @mails = readlog($in); #CSV fejlec # print BEJOVO ";BEJOVO LEVELEK;\n"; # print BEJOVO "Idopont;Felado;Cimzett\n"; # print KIMENO ";KIMENO LEVELEK;\n"; # print KIMENO "Idopont;Felado;Cimzett\n"; #fajlba iras if ( $mails[9] =~ /$domain/i ) { print KIMENO "$mails[2];$mails[9];$mai +ls[11]\n"; } elsif ( $mails[9] =~ /@/ ) { print BEJOVO "$mails[2];$mails[9];$mai +ls[11]\n"; } if ( $mails[8] =~ /$domain/i ) { print KIMENO "$mails[2];$mails[8];$mai +ls[10]\n"; } elsif ( $mails[8] =~ /@/ ) { print BEJOVO "$mails[2];$mails[8];$mai +ls[10]\n"; } #csv fajlok e-mail mellekletkent [cimzett]-nek #mpack program kell hozza! # system("mpack -s kimeno-`date -I` kimeno.csv $cimzett"); # system("mpack -s bejovo-`date -I` bejovo.csv $cimzett"); # system('rm bejovo.csv'); # system('rm kimeno.csv'); } close(KIMENO); close(BEJOVO); } sub readlog { my $line = $_[0]; chomp($line); my @mails; my $key = "<"; my $key2 = ">"; #Naplofajlok beolvasasa #amavis bejegyzesek kinyerese if ( $line =~ /amavis/ ) { #szokozonkent szetvalasztas es tombbe illesztes @mails = split ('$line'); #csak a kivalasztott napot vegye figyelembe if ( $mails[1] == $date ) { #"><" karakterek levagasa if ( $mails[9] =~ /@/ ) { $mails[9] =~ s/$key//g; $mails[9] =~ s/$key2//g; $mails[11] =~ s/$key//g; $mails[11] =~ s/$key2//g; } else { $mails[8] =~ s/$key//g; $mails[8] =~ s/$key2//g; $mails[10] =~ s/$key//g; $mails[10] =~ s/$key2//g; } } } return @mails; } while (<>) { push @data, $_; } if ( $opt_m eq "csv" ) { csv; }
The script is just half functional but useable. I think the passing of arrays between the subroutines aren't wokring properly. Thank You for your help!

In reply to passing arrays by ScOut3R

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2021-10-25 05:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (89 votes). Check out past polls.

    Notices?