ed!\n" }
> Now I'm thinking, it is quite impossible to dynamically create all those if
> tests. Perhaps I can just open a file for writing, write a new perl script
> which will have those codes, and execute it at the end.
>
For more dynamic you can try something like this...
$match = 1;
map { $match = 0 if ($word !~ /$_/) } @options;
if ($match) { print "All pattern matched\n" }
Hope that helps.
--
Robert Wohlfarth
>
Will a "for" loop work for your needs? The one below uses "substr" to
extract every two characters.
my $line="abcdefghijkl";
for (my $i = 0; $i < length( $line ); $i += 4) {
print substr( $line, $i, 2 ), "\n";
}
--
Robert Wohlfarth
xis_font('arial', 15) or die $graph->error;
> $graph->set_y_axis_font('arial', 15) or die $graph->error;
>
> Apache's error_log says:
>
> Cannot find TTF font: arial
>
Does setting the font path with GD::Text->font_path help? On Ubuntu,
"arial.ttf" is located in /usr/share/fonts/truetype/msttcorefonts.
--
Robert Wohlfarth
pport available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(-e:1):foreach (1..5) {print "$_\n"; }
DB<1> n
main::(-e:1):foreach (1..5) {print "$_\n"; }
DB<1> n
1
main::(-e:1):foreach (1..5) {print "$_\n"; }
DB<1> c 2
2
3
4
5
main::(-e:2):print "done\n";
DB<2>
The "c 2" continues until it reaches line 2 - outside of the loop. HTH
--
Robert Wohlfarth
e.
The code doesn't want to match ANY of the patterns. It needs a truth table
like this:
www * result
0 0 0
0 1 0
1 0 0
1 1 1
That truth table matches the AND operator. Does this make sense?
--
Robert Wohlfarth
good
> tutorial link would be really appreciated.
>
Check out one or more of the Perl web frameworks. I'm experimenting with
Catalyst right now: http://www.catalystframework.org/.
--
Robert Wohlfarth
t;C:\\commands\\AutoIT\\sch.bat\"";
> system("$cmd") or die "$!";
>
Try using 'psexec.exe' as the command. It's been a while since I've used my
Windows scripts. And I seem to remember having to use the extension. Or
maybe that's just old age...
--
Robert Wohlfarth
code do what you want?
foreach(my $key (sort keys %channels)) {
print $key, ' => ', $keys{$key};
}
--
Robert Wohlfarth
add subroutines
where they make sense - for code used by more than one place.
Leo <http://webpages.charter.net/edreamleo/front.html> is a pretty nice tool
fro writing programs in a literate style.
--
Robert Wohlfarth
t;) or die "cant open
> $bookingspath/$folder: $!\n"; while(defined(my $phone_data =
> readdir(DIR_PHONE))){
> if (substr($phone_data,0,8) eq 'PHONELOG'){
>
> &my_read_data_file($bookingspath,$folder,$phone_data);
> }
> } closedir(DIR_PHONE) ;
>
> }
>
> closedir(DIR) ;
>
>
For future reference, the File::Find module also traverses a directory tree.
--
Robert Wohlfarth
, for example,
also removes leading/trailing/multiple spaces.
--
Robert Wohlfarth
g;
> print MY_OUTPUT_FILE $line;
> }
>
Try this: $line =~ s/(\s)243 /${1}243rd /g;
Without the braces, Perl is looking for match number 1,243! Braces separate
the 1 from the 243.
--
Robert Wohlfarth
urring dates (like
"every Saturday"). If you can get a list of dates, then the count of the
list is the number that you want.
--
Robert Wohlfarth
$xmlresponse");
> # can't read the response in this manner
> ===
>
Try the "parse_string" method instead. The documentation says that XMLin
guesses based on the presence of "<" and ">" characters. It appears that
XMLin guesses wrong in your case.
"parse_string" explicitly expects an XML string. So there's no logic to
confuse.
--
Robert Wohlfarth
_first returns true and the line prints. What about $result? Perl
never called into the code for do_second, and $result never changed. We say
that Perl short circuited the evaluation. It stopped executing code as soon
as it knew the outcome of the logic statement.
--
Robert Wohlfarth
tes "print $first,
> $second, $third\n";
>
> 255, 255, 255
> 765
>
print "$first, $second, $third\n" prints a single, scalar value.
--
Robert Wohlfarth
;.
3. Loop from 2 to 1000...
1. Increment "Field ID" by 20.
2. Substitute the new "Field ID" for the old one, using regular
expressions.
3. Substitute the counter (L) in the field.
4. Write the entire block out to a new file.
Is that accurate?
--
Robert Wohlfarth
ady have extensions
>
The "-e" test will tell you if the target file already exists. For example:
if (-e $copyToFile) {
# Add extension here...
}
--
Robert Wohlfarth
executes at compile time - before "$oraenv" is set. Try the "require"
command:
require Env::Sourced;
Env::Sourced->import( $oraenv );
The perlfunc man page has more information about "use" and "require".
--
Robert Wohlfarth
m not
> sure how to proceed like which module I've have to use etc. any pointers
> would be much appreciated.
>
I've used XML::Parser <http://search.cpan.org/dist/XML-Parser/Parser.pm> to
do simple things. The documentation is here:
http://search.cpan.org/dist/XML-Parser/Parser.pm.
--
Robert Wohlfarth
;
> my @elems3 = split(//,$var);
>
The first two patterns match every character. When everything is a
separator, there's nothing left as data.
--
Robert Wohlfarth
',',$line);
@score_key=shift(@key);
return @key;
}
See http://perldoc.perl.org/functions/chomp.html for more information about
"chomp".
--
Robert Wohlfarth
et
> all the output which is too late.
>
See if the Expect<http://search.cpan.org/%7Ergiersig/Expect-1.21/Expect.pod>or
Expect::Simple<http://search.cpan.org/%7Edjerius/Expect-Simple-0.04/lib/Expect/Simple.pm>modules
will work. They let Perl control a child process using standard
into my
> current documentation methodology so that people can still enjoy my user
> docs, while I can review my devel docs within a separate `perldoc' page?
>
I've seen large projects like Moose put user documentation under
Moose::Manual::... The developer documentation is named after the actual
code module.
--
Robert Wohlfarth
se Bazaar at work (Windows). I create a branch on a USB stick to work
from home (Linux). On Monday, it's a matter of merging the USB branch back
into the original.
--
Robert Wohlfarth
th the new parsed row.
>>
>> Is this possible, and if so how can I do it?
>>
>
> It is possible, you just have to write the new data to a new file.
You might also want to look at the "-n", "-p", and "-i" command line options
for Perl (http://perldoc.perl.org/perlrun.html).
--
Robert Wohlfarth
treating "-a" as the
value for "-s" because the string "-a" immediately follows the option -s.
You could add validation on the value of "-s". For example...
GetOptions(
"n|name=s" => \$name,
"a|age=i" => \$age,
"s|sex=s" => \$sex,
) || die "Bad options\n";;
if ($sex !~ m/m(ale)?|f(emale)?/i) { die "Invalid gender $sex\n"; }
--
Robert Wohlfarth
message, "split" should not be called in a scalar context.
use strict;
use warnings;
sub xpto(@) {};
xpto( split(/\n/, "fv\nfg" ) );
--
Robert Wohlfarth
ng to continue from here once sub foo has ended and
I have not called exit here or in the sub?
}
elsif ($bar){
my_sub_bar();
}
else {
my_other_sub();
}
exit 0;
--
Robert Wohlfarth
oin personal_data on
user.id = personal_data.id where gender = ? and position = ?
order by lname limit ?,?
});
$sth->execute($gender, $role, $offset, $number_rows);
--
Robert Wohlfarth
rHash})
while (my ($key, $value) = each %{$rHash})
To access a single entry, you can do something like this: $value =
$rHash->{'field'};
--
Robert Wohlfarth
c.perl.org/perlopentut.html#Pipe-Opens.
--
Robert Wohlfarth
.looong string possibly with many E's...E.no capital e'
here...3456"
$string =~ m/E[^E]*$/;
The expression matches a capital E, followed by zero or more non-E
characters, and the end of the line.
--
Robert Wohlfarth
}
The first time through, @mytemp uses memory location 12345. The second time
through, @mytemp uses memory 12399. Third time, it's 12563. And so on... Now
you have a series of different memory locations, with different values for
$a, $b, and $c.
Does that make sense?
--
Robert Wohlfarth
.pm>.
It handles all of these details for you.
--
Robert Wohlfarth
miliar
> with js). thoughts?
>
Check out Catalyst (http://www.catalystframework.org/). It handles the
drudgery without forcing you into one way of doing things.
--
Robert Wohlfarth
--
>
Declare the subroutine before calling sort. Something like this...
sub cmpChrs();
foreach my $chr (sort cmpChrs keys %SAM) {
print "CHR=$chr\n";
}
The *sort* documentation for 5.12 shows three forms:
- sort SUBNAME LIST
- sort BLOCK LIST
- sort LIST
I&
elf...
>
> Jim Gibson wrote:
>
>> Install and use the File::Tee module from CPAN:
>>
>
> I researched the various options a while back and settled on Capture::Tiny.
>
Since this looks like a log file, you might also consider Log::Log4perl.
--
Robert Wohlfarth
pan.org/%7Epetdance/File-Next-1.06/Next.pm>module.
--
Robert Wohlfarth
d up with something like this...
$fieldMap{8} = 1023240136
$fieldMap{1218} = 0
$fieldMap{1} ="00a01a2bcdc7"
Perl expects the data to have a value for every key. The first error - odd
number of elements - means that Perl saw a key without a corresponding
value. The data has an odd number of elements. To save into a hash, it
should have an even number of elements.
--
Robert Wohlfarth
the below steps which i performed to send a message to
> log.
>
Take a look at
Log::Log4perl<http://search.cpan.org/%7Emschilli/Log-Log4perl-1.31/lib/Log/Log4perl.pm>(
http://search.cpan.org/~mschilli/Log-Log4perl-1.31/lib/Log/Log4perl.pm). It
handles multiple outputs seamlessly.
--
Robert Wohlfarth
7;, $h, $m;
> ++$h, $m = 0 if ++$m >= 60;
> }
>
I assume that Mike (the original poster) would get 50 times by substituting
"[0..50]" in place of "[0..24]".
my @sample = (shuffle @times)[0..24];
>
And this last piece then sorts the 50 random times into chronological order
for the cron job. It's very clever.
print "$_\n" foreach sort @sample;
--
Robert Wohlfarth
do this? Thanks
>
> @bet1 = (0,0,0,0);
> @bet2 = (0,0,0,1);
> @bet3 = (0,0,1,0);
>
> $random_bet_position = int(rand(3) + 1);
>
> @selected_bet = @{bet$random_bet_position);
>
@bets = ( [0,0,0,0], [0,0,0,1], [0,0,1,0] );
@selected_bet = @{$bets[$random_bet_position]};
--
Robert Wohlfarth
doc.perl.org/functions/sort.html> for examples of how to
arrange for an output ordering.* It's easy to miss if you didn't know to
look for it.
My limited understanding is that Perl handles the order internally. Code
should never rely on a specific order.
--
Robert Wohlfarth
t. Is
> that possible?
>
Would something like this meet your need? I found it on CPAN by
searching<http://search.cpan.org>for "Module".
http://search.cpan.org/~ivorw/Module-Optional-0.03/lib/Module/Optional.pm
--
Robert Wohlfarth
ers to func. Change the code like this:
print func() * 5, "\n";
--
Robert Wohlfarth
n vary the size (number of words) in each
record.
--
Robert Wohlfarth
text
> to xml file
> \n";
> ########
>
>
>$writer->endTag();
>print "closing page tag for the article num: ", $testCount,
> " \n";
>$testCount++;
>
> # print $testCount; print "\t";
> # if ($testCount == 10){
> # print "\n";
> # last;
> # }
>
>
>}#end if for en ar fr
>
>if (($$enText =~ /\[\[fr:/i)){
>
>#print $page->title, "\n";
>$EnFrCount ++;
>}
>
>if (($$enText =~ /\[\[ar:/i)){
>#print $page->title, "\n";
>$EnArCount ++;
>}
>#print "working \n";
>
> }# end for while loop (for each english article)
>
>
> $writer->endTag();
> $writer->end();
> $output->close();
>
>
> print "\n\n";
> print "English : ";
> print $EnCount;
>
> print "\n\n";
> print "English/Arabic/French : ";
> print $EnArFrCount;
>
> print "\n\n";
> print "English/Arabic : ";
> print $EnArCount;
>
> print "\n\n";
> print "English/French : ";
> print $EnFrCount;
>
>
>
> #removes any case sensativity from the very first letter of the title
> #but not from the optional namespace name
> sub case_fixer {
> my $title = shift;
>
> #check for namespace
> if ($title =~ /^(.+?):(.+)/) {
>$title = $1 . ':' . ucfirst($2);
> } else {
>$title = ucfirst($title);
> }
>
> return $title;
> }
>
--
Robert Wohlfarth
On Wed, Dec 21, 2011 at 10:37 AM, Shlomi Fish wrote:
> On Wed, 21 Dec 2011 09:48:19 -0600
> Robert Wohlfarth wrote:
>
> > On Tue, Dec 20, 2011 at 11:25 AM, Motaz SAAD
> wrote:
> >
> > > I am a beginner in perl and I have segmentation fault in my code. the
>
uot;which" turned up
File::Which<http://search.cpan.org/~adamk/File-Which-1.09/lib/File/Which.pm>.
It may meet your needs.
--
Robert Wohlfarth
On Sun, Jan 8, 2012 at 11:15 PM, Chris Stinemetz
wrote:
> How do I extract uniq elements from an array? Basically I want to
> preserve the order of the elements as they are first seen, but I would
> like to remove any duplicates.
>
You may want to check out List::MoreUtils on CPAN.
350 => 'AL',
351 => 'AL',
995 => 'AK',
996 => 'AK',
850 => 'AZ',
851 => 'AZ',
716 => 'AR',
717 => 'AR',
);
> my $customers_state = 'AZ';
my $customers_zip = '850';
if (
exists( $zips{$customers_zip} )
and $zips{$customers_zip} eq $customers_state
) { print 'yes'; }
else { print 'no'; }
--
Robert Wohlfarth
HTTP headers. I would
expect the script to run Template Toolkit, capture the results, and include
those results in an HTTP response.
--
Robert Wohlfarth
cell:
my $cell = $worksheet->{Cells}[$row][$column];
print $cell->value;
--
Robert Wohlfarth
p $line;
> @array = split(/\s+/, $line,-1);
> }
>
The "while" loop overwrites the contents of "@array". Every line overwrites
the previous one. I believe that you want a two dimensional array here.
--
Robert Wohlfarth
$val}) {
return @{$apcHash{$val}}{qw/start end/};
} else {
return ();
}
}
--
Robert Wohlfarth
quot;(.es.){3}" before running Perl. Those
extra slashes you added tell "bash" to not interpret the parenthesis.
You could also get around the problem by quoting the regular expression on
the command line, like this:
# ./grep.pl '(.es.){3}' /usr/share/dict/words
Hope that helps.
--
Robert Wohlfarth
s-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>
Take a look at the documentation for DBIx::Class::Schema::Loader::Base. It
explains how *make_schema_at* renames tables into classes.
http://search.cpan.org/~rkitover/DBIx-Class-Schema-Loader-0.07025/lib/DBIx/Class/Schema/Loader/Base.pm#naming
--
Robert Wohlfarth
and" keeps returning decimal numbers
between 3 and 4, like 3.4526180 and 3.9876261 and 3.1182304.
Instead of picking answers at random, what about shuffling the answers and
take the top 5? They're still in a random order. And you eliminate even the
possibility of an infinite loop. A modu
value, which
is what the warning tells you.
Perl expects program variables to start with a letter or underscore. So
"$a999" or "$num" work like you expected.
You can find more about variable names here:
http://perldoc.perl.org/perldata.html.
--
Robert Wohlfarth
It's
been a while since I've used it. I seem to recall that standard output gets
sent there.
--
Robert Wohlfarth
ple, and it's pretty easy to learn.
http://www.catalystframework.org/
--
Robert Wohlfarth
If you want to pause the actual program, then try Ctrl+Z. On a unix/linux
box that will work. See
http://www.gnu.org/software/bash/manual/bashref.html#Job-Control for more
information.
--
Robert Wohlfarth
On Wed, Sep 11, 2013 at 5:04 PM, Harry Putnam wrote:
> while(<$cmdh>) {
> print $fh;
> print;
>
I believe this code prints the file handle. Try this:
while(<$cmdh>){
print $fh $_;
print;
--
Robert Wohlfarth
the number part ?
>
There are two sets of capturing parenthesis:
* (91\d{10}|0\d{10}|[7-9]\d{9}|0\d{11}) = $1
* (\d+) = $2
The first set stores its match in $1 and the second set in $2. The pipe
(or) does not reset the capture counter back to 1. The counter strictly
goes from left to right.
--
Robert Wohlfarth
b is that objects represent "things". I think of
objects as managing state - the state of an individual "thing". Modules
with all class methods do not represent "things". They're just functions.
--
Robert Wohlfarth
);
This is a good example of how Perl flattens a parameter list. The
"&is_in_string(@ar, $c)" turns into "&is_in_string('t', 'd', 's', 'd');".
@_[0] only grabs the first parameter 't'. $_[1] grabs the second parameter
- the 'd' from @ar.
--
Robert Wohlfarth
\w+). The "\*" matches a
literal asterisk - which isn't in the string. So the match fails. Add the
"s" and it does what you expect.
--
Robert Wohlfarth
ot; and treats the rest of the line
like a comment. When passing "!@\#bsay0nd" to the shell, it interprets "#"
as a literal character instead.
--
Robert Wohlfarth
t;h1("hello world $ct"); # level 1 header
>>>
>>> print $q->end_html; # end the HTML
>>>
>>
> One more thing that came up while testing your code... Did you configure
> the ODBC datasource?
Is Microsoft Access installed on the server? DBI will need it to read the
file.
--
Robert Wohlfarth
09. No other line is simply
How about the 0D 0A at the end of the line? Unless the script used "chomp",
the exact line is "\r\n".
--
Robert Wohlfarth
mer's point of view).
>
It sounds like you want an event loop that triggers on socket activity.
Would something like AnyEvent::Socket
<http://search.cpan.org/~mlehmann/AnyEvent-7.07/lib/AnyEvent/Socket.pm>
work for you? I came across it by googling "perl socket event handler".
--
Robert Wohlfarth
tdir is a parameter to a function call. It should not have a semi-colon
after it.
--
Robert Wohlfarth
ks for any info… ;)
>
> Wags ;)
> WagsWorld
> Hebrews 4:15
> Ph(primary) : 408-914-1341
> Ph(secondary): 408-761-7391
>
--
Robert Wohlfarth
74 matches
Mail list logo