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. MillerH

    String match issue

    Use \Q...\E to escape regular expression special characters, like the any character '.' Also use word boundaries \b so that you don't match a substring like 1.1.1.100 use strict; use warnings; my $str = "group=1,101,102"; my $ip = "1.1.1.1"; if ($str =~ /\b\Q$ip\E\b/) { print "The string...
  2. MillerH

    Net::FTP

    The easiest solution is to download it to a subdirectory of cgi-bin, and then remove access from that subdirectory using .htaccess. Alternatively, you can use relative paths to access a directory outside of cgi-bin, but you'll of course have to set permissions right, which can be a challenge...
  3. MillerH

    Perl code using CUrl

    While it may not be helpful to point out, I must say that this code is very sloppy. It doesn't even appear to have use strict and use warnings turned on as none of the variables are declared with my. This does not make me optimistic toward the effectiveness and bug-free nature of this code...
  4. MillerH

    Copying Only Certain Images to Another Folder

    Use a glob use File::Copy; for my $file (<YOUR_DIRECTORY/*a.jpg>) { move($file, 'NEW_DIRECTORY'); } - Miller
  5. MillerH

    A bit of a regex problem

    As of Perl 5.18, smart match is experimental: "It is clear that smartmatch is almost certainly either going to change or go away in the future. Relying on its current behavior is not recommended." - Miller
  6. MillerH

    A bit of a regex problem

    As feherke has already stated, you should simplify your logic by taking advantage of the fact that you can execute code in the right side of a regex to selectively replace things. This is pretty close to what he's provided with just a couple small differences: use strict; use warnings; my...
  7. MillerH

    Comparing 3 vars if defined.

    This should give you what you desire. my @defined_vars = grep {defined $_} ($x, $y, $z); if (@defined_vars && ! grep {$_ ne $defined_vars[0]} @defined_vars) { print "All Vars equal each other if they are defined\n"; } The only special case that you didn't specify is what should happen...
  8. MillerH

    Perl Hand Coded Lexical Analyzer (Tokenizer)

    No need to reinvent the wheel using REGEX. This is already solved using PPI: http://search.cpan.org/perldoc?PPI - Miller
  9. MillerH

    How to create a directory.

    http://perldoc.perl.org/functions/chdir.html or http://perldoc.perl.org/File/Copy.html qw(move) - Miller
  10. MillerH

    Strict Pragma vs Error Log

    Quick answer: Yes, that is normal. Slightly longer answer: Just because your code includes "use strict;", does not mean that the external modules enforce that pragma as well. They can very easily do an explicit "no strict;" for the own scope. I've attempted to get rid of all of those...
  11. MillerH

    How to create a directory.

    Just read the following. It will also explain how to recursively create a directory: http://perldoc.perl.org/functions/mkdir.html - Miller
  12. MillerH

    Newby index function help

    Looks like you just need to be introduced to arrays and the foreach loop: #!/usr/bin/perl use strict; use warnings; # Grocery store inventory: my $lines = <<'END_OF_REPORT'; 0.95 300 White Peaches 1.45 120 California Avacados 5.50 10 Durian 0.40 700 Spartan Apples END_OF_REPORT my...
  13. MillerH

    replace or substitute....

    On a side note, I would advise you to remove the 'g' modifier, as global search and replace does not make sense in this situation. Also, if you really want to be hardcore, add a boundary condition since you want this to be removed from the front of the line only. $sentence =~...
  14. MillerH

    Can a reg ex do the job?

    The most reliable way to solve this type of problem is to break it up. Yes, you can write the solution to this in a single regular expression. However, the more complicated the regex, the more likely you are to overlook cases or introduce a bug. Therefore, use non-greedy matching to capture...
  15. MillerH

    Julian Date to Calender date conversion. Please help!

    The following will get you part of the way there. You'll still have to do the parsing and potentially install the DateTime module on your system: use DateTime; use strict; use warnings; my $dt = DateTime->new( year => 2011, month => 1, day => 1, ); $dt->add(days => 266); print...
  16. MillerH

    Find the minimum value in a column of an array

    You don't need a regex for this, just a queue that saves the lines with the current minimum value for the current group. If you can assume the lines are ordered, you could simplify the below logic, but the following will work. #!/usr/bin/perl -w use strict; use warnings; my @lines; my $min...
  17. MillerH

    Perl - parsing Windows CSV files with embedded quoted CR+LF, CR, or LF

    You need to either install them using strawberry perl's cpan. cpan -i Text::CSV Or you can just download the .pm's yourself and put them in your source tree. Also, I have to mention that perl 5.8 is legacy now so I have to encourage you to consider upgrading to perl 5.12. - Miller
  18. MillerH

    Perl - parsing Windows CSV files with embedded quoted CR+LF, CR, or LF

    I need to second the recommendation for Text::CSV my $csv = Text::CSV->new({ binary => 1, eol => "\n", quote_char => q{"}, }) or die "Cannot use CSV: ".Text::CSV->error_diag(); Even if you're worried about being able to include it on thousands of machines, just rely on the pure...
  19. MillerH

    logic help for newbie

    Why do arrays and hashes need to be mutually exclusive. Use both! # In loop for loading the files push @files, { id => $id, name => $name, size => $size, }; Assuming this isn't an assignment, I'd agree that rsync would work just fine. Good luck, - Miller
  20. MillerH

    website Form (Perl script) Error: &quot;Can't Save File&quot;

    I second the recommendation if not insistence that you include use strict; and use warnings; at the beginning of every script. It will require adjustment of your programming style, but it will save you so much headache in the end and make it more likely that you'll get assistance in forums when...

Part and Inventory Search

Back
Top