60 PerlMonks - Newest Nodes New nodes appearing on PerlMonks http://perlmonks.org/index.pl?node_id=30175 http://blogs.law.harvard.edu/tech/rss PerlMonks Newest Nodes XML Generator 961 PerlMonks 2015-05-05 00:55:53 rss,clean Mon May 4 14:55:53 2015 30 20150504145553 Mon May 4 14:55:53 2015 http://perlmonks.org/ Anonymous Monk Write an user answer inside an array Eth443 http://perlmonks.org/index.pl?node_id=1125643 Hi...again! The idea => The array is like the last one @bad_answer=( "Bad", "Bad to be honest", "Not good", "Not good enough" ); Now ... perlquestion Mon, 04 May 2015 23:22:10 +0000 http://perlmonks.org/index.pl?node_id=1125643 1125643 1125302 2015-05-04 19:22:10 Eth443 Loading an array with file names insta.gator http://perlmonks.org/index.pl?node_id=1125626 PERL noob here.I need to load an array with file names produced from a wildcard search on a Windows box. I would like to pass the wildcard to the PERL script if possible. Not having luck. ... perlquestion Mon, 04 May 2015 20:22:48 +0000 http://perlmonks.org/index.pl?node_id=1125626 1125626 1123335 2015-05-04 16:22:48 insta.gator Regular Expression Hiccup Mindsword http://perlmonks.org/index.pl?node_id=1125615 Hello, I have been working on a code for work and I found an odd glitch in my regular expression. I am looking through several blocks of texts for the Titles of some documents. The first title is ... perlquestion Mon, 04 May 2015 19:27:10 +0000 http://perlmonks.org/index.pl?node_id=1125615 1125615 1125611 2015-05-04 15:27:10 Mindsword Re^2: Loading an array with file names (Path::Tiny File::Find::Rule) Anonymous Monk http://perlmonks.org/index.pl?node_id=1125651 Yeah qr/\Q$first\E/ can just be $first as Path::Tiny uses <a href="http://search.cpan.org/perldoc/Text::Glob#glob_to_regex">Text::Glob#glob_to_regex</a>... note Tue, 05 May 2015 00:18:35 +0000 http://perlmonks.org/index.pl?node_id=1125651 1125651 961 2015-05-04 20:18:35 Anonymous Monk Re: Loading an array with file names (Path::Tiny File::Find::Rule) Anonymous Monk http://perlmonks.org/index.pl?node_id=1125650 <a href="https://metacpan.org/module/Path%3A%3ATiny">Path::Tiny</a> is a very good interface to readedir, very good substitute for <a href="http://perldoc.perl.org/functions/glob.html">glob</a> use Path::Tiny qw/ path cwd /; my $dir = cwd(); my( $first ) = @ARGV; # my @prfiles = gre... note Tue, 05 May 2015 00:14:52 +0000 http://perlmonks.org/index.pl?node_id=1125650 1125650 961 2015-05-04 20:14:52 Anonymous Monk Re^3: Write an user answer inside an array Anonymous Monk http://perlmonks.org/index.pl?node_id=1125649 Can you start the commenting? Comment as much as possible about every line of the program... note Tue, 05 May 2015 00:07:17 +0000 http://perlmonks.org/index.pl?node_id=1125649 1125649 961 2015-05-04 20:07:17 Anonymous Monk Re^5: Detecting memory leaks. Anonymous Monk http://perlmonks.org/index.pl?node_id=1125648 If you have one circular references, you probably have more ... try <a href="https://metacpan.org/module/Devel%3A%3ACycle">Devel::Cycle</a>/<a href="https://metacpan.org/module/Devel%3A%3ALeak">Devel::Leak</a> ... note Tue, 05 May 2015 00:05:55 +0000 http://perlmonks.org/index.pl?node_id=1125648 1125648 961 2015-05-04 20:05:55 Anonymous Monk Re^2: Reading a huge input line in parts aaron_baugher http://perlmonks.org/index.pl?node_id=1125647 The performance on that may not be as bad as you think. I tried benchmarking my read-by-chunks solution against a change-the-input-record-separator-to-space solution. The latter makes the code ... note Mon, 04 May 2015 23:54:35 +0000 http://perlmonks.org/index.pl?node_id=1125647 1125647 597736 2015-05-04 19:54:35 aaron_baugher Re^2: Write an user answer inside an array Eth443 http://perlmonks.org/index.pl?node_id=1125646 Yey, thanks I'm quite noobie as you know, can you comment a little bit? xD I hate just copy and paste the code if I cannot understand it.. ... note Mon, 04 May 2015 23:35:55 +0000 http://perlmonks.org/index.pl?node_id=1125646 1125646 1125302 2015-05-04 19:35:55 Eth443 Re: Write an user answer inside an array jeffa http://perlmonks.org/index.pl?node_id=1125645 As discussed in the CB, you'll need to store the contents outside of RAM, such as a file. The following code will bootstrap the file if necessary and query the user for feelings and how they feel... note Mon, 04 May 2015 23:32:34 +0000 http://perlmonks.org/index.pl?node_id=1125645 1125645 18800 2015-05-04 19:32:34 jeffa Re: Write an user answer inside an array AnomalousMonk http://perlmonks.org/index.pl?node_id=1125644 I haven't been following along in the CB so this may not be apropos, but maybe something like: c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my @answers = ('Bad', 'Good', 'Not good ... note Mon, 04 May 2015 23:31:06 +0000 http://perlmonks.org/index.pl?node_id=1125644 1125644 634253 2015-05-04 19:31:06 AnomalousMonk Re^3: Reading a huge input line in parts (Handles multi-digit numbers!) BrowserUk http://perlmonks.org/index.pl?node_id=1125642 Could this not be simplified? And what happens when your buffer size splits a multi-digit number in two? Ie. Run your code against this input: 123 456 ... note Mon, 04 May 2015 22:37:53 +0000 http://perlmonks.org/index.pl?node_id=1125642 1125642 171588 2015-05-04 18:37:53 BrowserUk Re^3: Reading a huge input line in parts aaron_baugher http://perlmonks.org/index.pl?node_id=1125641 In that case, I'd check the end of the buffer for digits, and if there are any, trim them off and save them to prepend to the next buffer that you read in. But you don't want to do that if it's ... note Mon, 04 May 2015 22:36:18 +0000 http://perlmonks.org/index.pl?node_id=1125641 1125641 597736 2015-05-04 18:36:18 aaron_baugher Re^3: Regular Expression Hiccup AnomalousMonk http://perlmonks.org/index.pl?node_id=1125640 ... "X-ray" simply fails. What others have written remains true: a '-' (dash; hyphen) character is not the same as (and will not match) a ' ' ... note Mon, 04 May 2015 21:46:31 +0000 http://perlmonks.org/index.pl?node_id=1125640 1125640 634253 2015-05-04 17:46:31 AnomalousMonk Re^2: Using Look-ahead and Look-behind Anonymous Monk http://perlmonks.org/index.pl?node_id=1125639 note Mon, 04 May 2015 21:45:26 +0000 http://perlmonks.org/index.pl?node_id=1125639 1125639 961 2015-05-04 17:45:26 Anonymous Monk Re: Loading an array with file names GotToBTru http://perlmonks.org/index.pl?node_id=1125636 * means one thing in filename wildcards and another in regexes. It does work in glob(). use Cwd; my $dir = getcwd; opendir DIR, $dir; my $filter = shift; $qfilter = quotemeta $filte... note Mon, 04 May 2015 21:26:38 +0000 http://perlmonks.org/index.pl?node_id=1125636 1125636 844862 2015-05-04 17:26:38 GotToBTru Re: Reading a huge input line in parts CountZero http://perlmonks.org/index.pl?node_id=1125635 I get a different result when using a space as the delimiter.The zero at the end of the line gets recognized OK, but it is the first figure at the next line that gets skipped. So this small test pr... note Mon, 04 May 2015 21:25:11 +0000 http://perlmonks.org/index.pl?node_id=1125635 1125635 198160 2015-05-04 17:25:11 CountZero Re^3: Regular Expression Hiccup jeffa http://perlmonks.org/index.pl?node_id=1125634 The following works for me: use strict; use warnings; use feature 'say'; my $text = do{ local $/; }; say $text =~ /Screening Ligands by X-ray crystallography/ ? 'MATCH!': ... note Mon, 04 May 2015 21:17:32 +0000 http://perlmonks.org/index.pl?node_id=1125634 1125634 18800 2015-05-04 17:17:32 jeffa Re^2: Reading a huge input line in parts kroach http://perlmonks.org/index.pl?node_id=1125633 This is not different than my first approach. Replacing newline here occurs only after the data is read, so it doesn't change anything. Since $/ was changed, the newline is just like any other charact... note Mon, 04 May 2015 21:16:37 +0000 http://perlmonks.org/index.pl?node_id=1125633 1125633 1115757 2015-05-04 17:16:37 kroach Re^2: Comparison between a string and an array Eth443 http://perlmonks.org/index.pl?node_id=1125632 I tried putting Ba and doesn't match as you said, actually for me it's working, but I will considere your answer/reflexion for future codes. Thanks... note Mon, 04 May 2015 21:09:18 +0000 http://perlmonks.org/index.pl?node_id=1125632 1125632 1125302 2015-05-04 17:09:18 Eth443 Re: Loading an array with file names jeffa http://perlmonks.org/index.pl?node_id=1125631 If you are only performing simple, ad hoc tasks then this is one of those great times when you can get away with writing on-the-fly one-liners. Let's say you wanted to do something like rename th... note Mon, 04 May 2015 21:01:46 +0000 http://perlmonks.org/index.pl?node_id=1125631 1125631 18800 2015-05-04 17:01:46 jeffa Re^3: Reading a huge input line in parts CountZero http://perlmonks.org/index.pl?node_id=1125630 Now that is long indeed!Assuming you can read and process a gigabyte of data per second, handling a line that long will take you more than a month.... note Mon, 04 May 2015 21:00:30 +0000 http://perlmonks.org/index.pl?node_id=1125630 1125630 198160 2015-05-04 17:00:30 CountZero Re: Regular Expression Hiccup hdb http://perlmonks.org/index.pl?node_id=1125629 There are also different capitalizations of "crystallography" in this thread. Have you tried matching case-insensitive? if ($text =~ /Screening Ligands by X-ray Crystallography/i... note Mon, 04 May 2015 20:48:56 +0000 http://perlmonks.org/index.pl?node_id=1125629 1125629 1021810 2015-05-04 16:48:56 hdb Re: Loading an array with file names edimusrex http://perlmonks.org/index.pl?node_id=1125628 You could do something like this using back ticks to issue a dos command and capture the results in an array #!/usr/bin/perl $folder = 'C:'; $input = $ARGV&#91;0&#93;; @array = `dir /b ${fol... note Mon, 04 May 2015 20:40:47 +0000 http://perlmonks.org/index.pl?node_id=1125628 1125628 955783 2015-05-04 16:40:47 edimusrex Re: Loading an array with file names Corion http://perlmonks.org/index.pl?node_id=1125627 Instead of doing the work yourself, use a module: use File::Glob 'bsd_glob'; my @files= bsd_glob $dir; print "$_\n" for @files; ... note Mon, 04 May 2015 20:28:12 +0000 http://perlmonks.org/index.pl?node_id=1125627 1125627 5348 2015-05-04 16:28:12 Corion Re: Regular Expression Hiccup GotToBTru http://perlmonks.org/index.pl?node_id=1125625 Some titles have "X-ray" and some have "X ray"? if ($text =~ /Screening Ligands by X<a href="?node=%20-"> -</a>ray Crystallography/) { say "MATCH!"; } ... note Mon, 04 May 2015 20:22:20 +0000 http://perlmonks.org/index.pl?node_id=1125625 1125625 844862 2015-05-04 16:22:20 GotToBTru Re^2: Regular Expression Hiccup Mindsword http://perlmonks.org/index.pl?node_id=1125624 Sorry for the late reply. Here's the block of text I am searching. --------- EFETCH RESULT(1..3): &#91; 1. Methods Mol Biol. 2014;1140:315-23. doi: 10.1007/978-1-4939-0354-2_23. Screenin... note Mon, 04 May 2015 20:21:32 +0000 http://perlmonks.org/index.pl?node_id=1125624 1125624 1125611 2015-05-04 16:21:32 Mindsword Re: Regular Expression Hiccup Laurent_R http://perlmonks.org/index.pl?node_id=1125623 The dash (or hyphen) has no special meaning in general regular expressions (except in character classes). So there is absolutely no problem with: if ($text =~ /Screening Ligands by X-ray Crystal... note Mon, 04 May 2015 20:18:20 +0000 http://perlmonks.org/index.pl?node_id=1125623 1125623 992570 2015-05-04 16:18:20 Laurent_R Re: Reading a huge input line in parts flexvault http://perlmonks.org/index.pl?node_id=1125622 Hello kroach, I tried to compare 2 way of doing this, and clearly letting Perl do the buffering wins out, but with the size of your l... note Mon, 04 May 2015 20:08:01 +0000 http://perlmonks.org/index.pl?node_id=1125622 1125622 733061 2015-05-04 16:08:01 flexvault Re: Comparison between a string and an array edimusrex http://perlmonks.org/index.pl?node_id=1125621 Try this my @answer=( "Bad", "Good", "Not good enough" ); chomp(my $user_answer=); if (grep (/\b$user_answer\b/, @answer)){ print "Ok\n"; }... note Mon, 04 May 2015 20:07:17 +0000 http://perlmonks.org/index.pl?node_id=1125621 1125621 955783 2015-05-04 16:07:17 edimusrex Re^2: Reading a huge input line in parts kroach http://perlmonks.org/index.pl?node_id=1125620 The lines in question can be up to 2 700 000 000 000 000 characters.... note Mon, 04 May 2015 19:53:58 +0000 http://perlmonks.org/index.pl?node_id=1125620 1125620 1115757 2015-05-04 15:53:58 kroach Re: Regular Expression Hiccup Anonymous Monk http://perlmonks.org/index.pl?node_id=1125619 Literal strings in regular expressions must match character-for-character. The "-" is just as significant as any other character, it isn't discarded or ignored "just because". A "-" is different ... note Mon, 04 May 2015 19:50:34 +0000 http://perlmonks.org/index.pl?node_id=1125619 1125619 961 2015-05-04 15:50:34 Anonymous Monk Re^3: In my home, the TV remote control is ... GotToBTru http://perlmonks.org/index.pl?node_id=1125618 Agreed. However, previous to the soundbar, audio from the TV/game console/media player came thru the stereo tuner, which is too old for remote control. The pain of the additional remote is assuaged... note Mon, 04 May 2015 19:41:49 +0000 http://perlmonks.org/index.pl?node_id=1125618 1125618 844862 2015-05-04 15:41:49 GotToBTru Re: Regular Expression Hiccup Corion http://perlmonks.org/index.pl?node_id=1125617 /X ray/ will never match "X-ray" If you want a placeholder, the dot (".") is the placeholder character in regular expressions (<a href="http://perldoc.perl.org/perlre.html">perlre</a>).... note Mon, 04 May 2015 19:40:13 +0000 http://perlmonks.org/index.pl?node_id=1125617 1125617 5348 2015-05-04 15:40:13 Corion Re: In my home, the TV remote control is ... Lady_Aleena http://perlmonks.org/index.pl?node_id=1125616 The remotes are under control of whoever i watching TV, if we are both watching TV, I am given the remotes. (I have to mute commercials, he doesn't care.) ... note Mon, 04 May 2015 19:38:34 +0000 http://perlmonks.org/index.pl?node_id=1125616 1125616 161890 2015-05-04 15:38:34 Lady_Aleena Re^2: Reading a huge input line in parts (Handles multi-digit numbers!) GotToBTru http://perlmonks.org/index.pl?node_id=1125614 Could this not be simplified? sub genBufferedGetNum { return sub { @buf = do{ local $/ = \10; split ' ', }; return @buf; }; } my $getNum... note Mon, 04 May 2015 19:19:55 +0000 http://perlmonks.org/index.pl?node_id=1125614 1125614 844862 2015-05-04 15:19:55 GotToBTru Re^2: Mechanize::Firefox can't get it to scroll WonderLemming http://perlmonks.org/index.pl?node_id=1125613 Hmm, that didn't work for me.... note Mon, 04 May 2015 19:16:52 +0000 http://perlmonks.org/index.pl?node_id=1125613 1125613 1125596 2015-05-04 15:16:52 WonderLemming Szarley Szarley http://perlmonks.org/index.pl?node_id=1125637 user Mon, 04 May 2015 21:36:47 +0000 http://perlmonks.org/index.pl?node_id=1125637 1125637 1125637 2015-05-04 17:36:47 Szarley Mindsword Mindsword http://perlmonks.org/index.pl?node_id=1125611 user Mon, 04 May 2015 19:10:11 +0000 http://perlmonks.org/index.pl?node_id=1125611 1125611 1125611 2015-05-04 15:10:11 Mindsword