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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search results for query: *

  1. mikevh

    system function problem: help

    TrojanWarBlade is right. But I'd suggest the qq() function to avoid the backslashed quotes. $cmd = qq("$dir/etc/run.bat" "$dir/build/edu/umd/simfinder/Eval"); HTH
  2. mikevh

    stepping through arrays

    ...map {quotecol($_)} $k, @{$HoH{$k}}{@innerkeys}), "\n"; } sub quotecol { # Return argument quoted. local $_ = shift; /^".*"$/? $_: qq("$_"); } Rest as before. Output KEY,a,b,c,d,e "aaa","some_a_data","some_b_data","some_c_data","some_d_data",""...
  3. mikevh

    stepping through arrays

    ...Here's a hash-of-hashes approach: #!perl use strict; use warnings; my $outerkey; my @innerkeys; my %HoH; while (<DATA>) { chomp; /^\s*$/ && next; /^-/ && next; if (/^record\s+(.+)/) { $outerkey = $1; } elsif (/^\s+item\s+(.+):\s+(.*)/) { # add $1 to...
  4. mikevh

    Formatting Dates

    One way is to use the Date::Calc module, e.g. #!perl use strict; use warnings; use Date::Calc qw(Decode_Date_EU); my $file_ts = '01-JAN-2005'; my ($year, $month, $day) = Decode_Date_EU($file_ts); my $out = sprintf '%02d/%02d/%04d', $month, $day, $year; print $out, "\n"; How you expect to get...
  5. mikevh

    Formatting Dates

    It's not clear to me what you're trying to do. Are you trying to format a file's timestamp? (The name $FILE_TS suggests this.) You're still not showing enough of your code. Cut and paste it inside tags. If you don't know about tags, click on ProcessTGML below the box where you type your...
  6. mikevh

    Formatting Dates

    I'd guess your $tm doesn't contain what you think it contains. How's it getting set? Can we see a bit more of your code, please?
  7. mikevh

    Array of Hashes

    If your array elems are hash references 1. Dereference the element as a hash 2. Use the keys function to get a list of hash keys 3. Itererate over the keys and use the keys to look up the values. This should do it. for $i ( 0 .. $#cleanedData ) { $aref = $cleanedData[$i]; $n =...
  8. mikevh

    Installing documentation for modules

    Could it be pod2html? Haven't used it myself, but this might be what you're looking for.
  9. mikevh

    Help using variables in a reg. exp...

    You could make the hash values code references. This seems to do what you want. #!perl use strict; use warnings; my %jason = ( red => sub{/^one/ && /two/ || /^three/ && /four/}, green => sub{/^five/ && /six/ || /^seven/ && /eight/}, ); while (<DATA>) { my $found = 0; for my...
  10. mikevh

    manipulating csv file with perl

    ...= split(/,(?!\s+)/, $line); # quote columns containing commas @columns = quotecol(@columns); for (2,7) { $columns[$_] =~ s/^.*://; $columns[$_] =~ s/%.*$//; } print OUTTAX join(",", @columns [0,2,3,5..$#columns]), "\n"; } sub quotecol { # quote...
  11. mikevh

    manipulating csv file with perl

    Fields in a .csv file that contain commas are supposed to be surrounded in double quotes. Text::CSV_XS should handle this correctly. So I'm guessing your file is not a standard .csv file. Can you post a representative sample of your file, surrounded in tags? If you don't know about tags...
  12. mikevh

    Display number of matching regex components

    Hmm, you mean something like this? #!perl use strict; use warnings; my $line = "1.2 blah 147 3.5 hey 9999 14.75"; my $pattern = qr/\d+\.\d+/; my @found; if (my @list = $line =~ /($pattern)/g) { push(@found, [ @list ]); } for (@found) { print join("\t", @$_), "\n"; }
  13. mikevh

    manipulating csv file with perl

    This'll give it to you as ddmmyy. my ($mday, $mon, $year) = (localtime(time))[3..5]; my $cdate = sprintf "%02d" x 3, $mday, $mon+1, $year%100; my $filename = "taxout${cdate}.csv"; open (OUTTAX, ">$filename") or die "$!";
  14. mikevh

    Strange split question . . .

    Here's something I wrote a while back that you may find useful. The heart of this is the parsefixed routine. You pass it a line of fixed-width data and a list with the starting positions and lengths of your data fields, and it returns the fields in an array. This program assumes the first...
  15. mikevh

    Using variables for File Handles

    dmazzini, I don't see where you're using a variable as a file handle? erdman, you can do it like this. #!perl use strict; use warnings; my $HANDLE; open($HANDLE, ">erdman.txt") || die qq(Can't open "erdman.txt"!\n); my @array = qw(apples oranges peaches pears grapes); printReport($HANDLE...
  16. mikevh

    manipulating csv file with perl

    ...chomp $line; if (my $status = $csv->parse($line)) { my @columns = $csv->fields; for (2,7) { $columns[$_] =~ s/^.*://; $columns[$_] =~ s/\*.*$//; } print OUTTAX join(",", @columns[0,2,3,5..$#columns]), "\n"; } else { warn...
  17. mikevh

    Parse::Nessus::NBE

    I don't see a use statement in your code. use Parse::Nessus::NBE qw(vars or subs from module); You need this in order to use the module. Take a look at perldoc perlmod.
  18. mikevh

    Help with Reading files from directory

    foreach my $f (@files){ next if ($name eq "."); next if ($name eq ".."); What is $name here? Don't you mean $f? sub addFiletoHash($f,$loc){ my $folder = shift; my $path = $loc; print "Folder is $folder and location is $loc\n"; chdir($f) or die "Unable to...
  19. mikevh

    Grab output of file called by system()

    Use backticks or qx() if you want to capture the output. Also, the string comparison operator is eq, not ==. The latter is for comparing numbers, not strings.
  20. mikevh

    get contents of a whole file

    Try perldoc -q "entire file" at a command prompt. Should tell you everything you need to know, and maybe then some.

Part and Inventory Search

Back
Top