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

Recent content by sackyhack

  1. sackyhack

    comparing two files

    # Assumptions: # Each 'fielda' value appears at most ONCE in the master # file and ONCE in the log file. You may want to add # checks to this program to ensure that these assumptions # are true. # # The ordering of the master file will be mixed up # by the hash. This is assumed to be...
  2. sackyhack

    searching directory/files.

    I think your code nesting is a bit goofed up. By the time you get to your if statement $username has the first line of the last stats.cgi file in it. You need something like this I think... opendir(DIR, "$basedir"); @members = readdir (DIR); closedir(DIR); $result =...
  3. sackyhack

    Variables as pattern matching options

    Another way to do this is to use embedded pattern-match operators (see man perlre). These work by adding a string with the pattern match parameters before the regular expression. For example (building on your code): # $case will contain embedded pattern-match operator $case = "(?i)&quot...
  4. sackyhack

    Sorting Hash Arrays - newbie

    Try this slightly modified version of your code: $items[0]{title} = "Smoke on the water"; $items[0]{artist} = "Deep Purple"; $items[1]{title} = "Kill'em all"; $items[1]{artist} = "Metallica"; foreach $item (@items) { print ${$item}{title}...
  5. sackyhack

    removing items from an array

    I think your routine will work and in a time acceptable to you. However using a hash would be more efficient. Your program is executing grep on your songlist array once for each playlist entry. Try this algorithm: - Initialize hash using .mp3 filenames as keys foreach $songname (@mp3s) {...
  6. sackyhack

    Recommended data file size..?

    print file "blah\n"; foreach (@file) { print file "@file\n"; } If @file is an array of 10,000 elements, your code will write out the entire array 10,000 times. I think your second line should be either foreach (@file) {print file "$_\n"; } or print file @file...
  7. sackyhack

    removing items from an array

    @myarray = ( "A File - My File1.txt", "A File - My File2.txt" ); $line = "File=A File - My File1.txt\n"; chop ($substring = substr ($line, index ($line, "=") + 1)); @myarray = grep (!/$substring/, @myarray) if ($line =~ /^File/); foreach (@myarray) {...
  8. sackyhack

    Problems with hash

    I've done some testing and it looks like like I was completely wrong about returning hashes. My 'solution' would work, but only as well as your original code. I think the first problem pointed out in hmerrill's post is probably your problem. If you want to call a sub that is declared later in...
  9. sackyhack

    Problems with hash

    You can't return a hash from a function like that. You need to use references or return the hash as an array. The returned array is assigned into the hash with the even numbered elements (0, 2, 4, ...) being the keys and the odd elements as the values (element 1 is the value for the key in...
  10. sackyhack

    Escaping '$'

    hmerrill's '\' escape works with a double-quoted string. You don't need to escape a '$' inside a single-quoted string. print '$1,000'; print "\n"; print "\$1,000"; print "\n";
  11. sackyhack

    Parsing data to seperate lines("newbie)

    When a browser renders HTML it ignores things like newlines. What you need is some <BR> to tell the browser to start a new line. print &quot;$FORM_DATA{'personname'}<BR>\n&quot;; print &quot;$FORM_DATA{'address'}<BR>\n&quot;; print &quot;$FORM_DATA{'phone1'}<BR>\n&quot;; print...
  12. sackyhack

    How do you sort array?

    You'd need to use cmp instead of <=> for the parts of the split that you want sorted alphabetically: {(my $a1, $a2) = split(/~/, $a); (my $b1, $b2) = split(/~/, $b); $a1 <=> $b1 || $a2 cmp $b2} That code is pretty cool. <=> and cmp evaluate to 0 when the values are equal, so the second...
  13. sackyhack

    How do you sort array?

    You just need to split the key and do a numeric sort on the first part: %h = ( &quot;2~afga~X&quot; => &quot;b&quot;, &quot;12~ands~L&quot; => &quot;l&quot;, &quot;1~ijdf~N&quot; => &quot;a&quot;, &quot;3~FDSAF~V&quot; => &quot;c&quot;, &quot;7~Udsd~U&quot; => &quot;g&quot...
  14. sackyhack

    A true Challenge : How can I remove a game file from workstations?

    Digest::MD5 on CPAN would help you in this case.
  15. sackyhack

    adding all elements of an array

    You could use map or grep, but I'm not sure that would be any faster: my $total_size = 0; map {$total_size += $_} @array; or my $total_size = 0; grep {$total_size += $_} @array;

Part and Inventory Search

Back
Top