This is where I am stuck. I don't know how to open each of the other files in @priv and @pub and write them to dynamically created arrays; one for each file. And, as I'm writing this I just realized that in order to be accurate, I will need to:#!/usr/local/bin/perl use strict; use Array::Compare; ############################## # Define some variables here # ############################## my ( @pub, @priv, @as, @files, @lines ); my ( $num, $from, $to, $AS, $privstring, $pubstring, $element, $beg_priv_file, $beg_pub_file, $comp_file, $as_dir, $line ); my $dir = "path-to-peering-files"; ################### # test invocation # ################### die "\nUsage: $0 <AS> <yyyymmdd-yyyymmdd>\n This program will take peering files, as per AS specified on the command line where AS = [123, 456, 789, 111, 222] choose multiple AS's by comma-separating them for example, \"123,456,789\" -a to process all valid AS's\n\n" unless @ARGV; unless (($from, $to) = $ARGV[1] =~ /(\d{8})-(\d{8})/) { die "Invalid dates or date format\n"; } unless ($from < $to){ die "Invalid date range\n"; } $AS = $ARGV[0]; my @as = split(",", $AS); foreach $num(@as){ die "AS $num is not recognized. Please choose [123, 456, 789, 111, 222]\n" unless ($num == 123 || $num == 456 || $num == 789 || $num == 111 || $num == 222 || $num == "-a"); } ######################### # Set AS(s) to process # ######################### if ($AS == "-a"){ @as = qw(123 456 789 111 222); } ############################## # Begin file processing here # ############################## foreach $num(@as) { &get_routers($num); } ############### # SUBROUTINES # ############### sub get_routers { #################################### # set file prepend according to AS # #################################### if ($num = "123") { $privstring = "private-peering."; $pubstring = "public-peering."; $as_dir = "$dir/AS$num"; } elsif ($num = "456") { $privstring ="global-public-peering."; $pubstring = "global-private-peering."; $as_dir = "$dir/AS$num"; } elsif ($num = "789") { $privstring = "ebiz-public-peering."; $pubstring = "ebiz-private-peering."; $as_dir = "$dir/AS$num"; } elsif ($num = "111") { $privstring = "euro-public-peering."; $pubstring = "euro-private-peering."; $as_dir = "$dir/AS$num"; } else { $privstring = "asia-public-peering."; $pubstring = "asia-private-peering."; $as_dir = "$dir/AS$num"; } } opendir (DIR, $as_dir) || die "Cannot open $as_dir: $!.\nRestart this program without AS$AS, or go find out what's wrong, and re-run the program.\n"; @files = grep { /(\d{8})/ && $1 >= $from && $1 <= $to } readdir DIR; ############################################### # push private-peering files into an array, # # and public-peering files into another array # ############################################### foreach my $t(@files){ if ($t =~/^$privstring(\d+$)/){ push(@priv, $t); } elsif ($t =~/^$pubstring(\d+$)/){ push(@pub, $t); } } $beg_priv_file = shift(@priv); $beg_pub_file = shift(@pub); open (BEG_PRIV_FILE, "$as_dir/$beg_priv_file") || die "Cannot open: $!\n"; LINE: while (<BEG_PRIV_FILE>){ chomp; if (/unknown/) { next LINE;} elsif (/shutdown/) { next LINE;} @lines = $_; }
I'm really stuck. Can anyone help me out?now this is pseudo-code, so don't bash me here! if $element(@beginning_file) doesn't exist in @next_file Print something to STDOUT that I will define later. AND if $element(@next_file) doesn't exist in @beginning_file Print something else to STDOUT that I will define later
In reply to Arrays of files from an array of file names by Tuna
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |