perl

How can I split a line when some fields contain spaces?

I have a text file that I extracted from a PDF file. It's arranged in a tabular format; this is part of it: DATE SESS PROF1 PROF2 COURSE SEC GRADE COUNT 2007/09 1 RODRIGUEZ TANIA DACSB 06500 001 A 3 2007/09 1 RODRIGUEZ TANIA DACSB 06500 001 A- 2 2007/09 1 RODRIGUEZ TANIA DACSB 06500 001 B 4 2007/09 1 RODRIGUEZ TANIA DACSB 0...

How do I truncate, create, write, and move around in a file in Perl?

Is it possible to do these things in Perl? truncate a file if already exists, and create,and write, and moving the cursor to end for append ...

How do I send a password to a command I start with Perl's Expect.pm?

I have the following script, #!/usr/bin/perl use strict; use warnings; use Net::SSH::Perl; use Expect; my $logs = "logs"; open(LOG,'>>',"$logs") or die "can't logs $!\n"; my $domain = 'domain.com'; my @host = qw/host/; foreach my $host (@host) { my $cmd = "passwd user1"; my $sshost = join('.', $host, $domain); my $ssh = Net...

In Perl, how can I convert arrays I read from database into a hash?

Basically, I'm querying a database and I need to convert the resultant array to a hash. I query the database as follows my $sth = $dbw->prepare($sql); while (@rows = $sth->fetchrow_array()) { ... ... } Now, I need to create a hash such that rows[0] is the key and rows[1],rows[2],rows[3] are the values. For each record read, a new h...

How should I delete hash elements while iterating?

I have fairly large hash (some 10M keys) and I would like to delete some elements from it. I usually don't like to use delete or splice, and I wind up copying what I want instead of deleting what I don't. But this time, since the hash is really large, I think I'd like to delete directly from it. So I'm doing something like this: forea...

What can be wrong with word count program?

I've got a question in my test: What is wrong with program that counts number of lines and words in file? open F, $ARGV[0] || die $!; my @lines = <F>; my @words = map {split /\s/} @lines; printf "%8d %8d\n", scalar(@lines), scalar(@words); close(F); My conjectures are: If file does not exist, program won't tell us about that. ...

Is it possible to run a Perl Script on MS Surface?

And if this is possible, how can I do that? ...

How can I output a large HTML table in a Perl CGI program without freezing the browser?

I have this Perl CGI program and I allow the user to select the number of data to view on this HTML table. I go through a foreach ... foreach ... and print each row. There is an issue with the Perl CGI script when it prints over 3,000 rows of data and my Firefox window becomes unresponsive. I am also linking dataTable jquery. What app...

Perl: Extract data from logs into a report

I have some logs in a directory: /test/report. The logs are named: a.log, b.log, c.log. The content of a.log is below: Input 1 ---- Number of records := 101 Input 2 --- Num of of records := 101 Input 3 --- Num of records := 101 The content of b.log is below: Input1 ------- Number of records := 88 Input 2 ----- Num of of rec...

How can I call a Perl script inside HTML page?

I have a single HTML file, how I use a Perl script(date/hour) in the HTML code? My goal: show a date/hour in HTML Obs.: alone both script are ok. Example: HTML File: <html> <body> code or foo.pl script </body> </html> Perl script(foo.pl): #!/usr/local/bin/perl use CGI qw/:push -nph/; $| = 1; print multipart_init(-boundary=>'----here...

How can I pass two arrays and a string to a Perl subroutine?

How can I pass two arrays and a string to a sub? Here's what I'm trying to do: use strict; use warnings; my @x = qw(AAAA BBBB CCCC DDDD EEEE); my @y = qw(1111 2222 3333 4444 5555); my $z = "hello"; Hello(@x,@y,$z); exit(0); sub Hello { my (@x,@y,$z) = @_; print "$_\n" for @x; print "$_\n"; print "$_\n" for @y; ...

Is using prototypes to declare array reference context on subroutine args a Good Thing in Perl?

In the linked SO answer, Eric illustrates a way to call a subroutine, which accepts arrays by reference as arguments, and use the prototypes to allow the caller code to pass the array names without using reference operator \@; the way built-ins like push @array, $value do. # Original code: sub Hello { my ($x_ref, $y_ref) = @_; ...} Hell...

HTML::TableExtract: applying the right attribs to specify the attributes of interest

I tried to run the following Perl script on the HTML further below. My problem is how to define the correct hash reference, with attribs that specify attributes of interest within my HTML <table> tag itself. #!/usr/bin/perl use strict; use warnings; use HTML::TableExtract; use YAML; my $table = HTML::TableExtract->new(keep_html=>0, d...

How do I run code only after Perl's Find::Find finishes?

Perl question for you: #!/usr/bin/perl use File::Find; #Find files find(\&wanted, $dir); sub wanted { #Do something } #Done going through all files, do below: other stuff { } So, I basically want to parse a directory and find certain kinds of files. I can do that successfully with File::Find. However, my next step is, once ...

How can I evaluate a function or method within quotations in Perl?

Possible Duplicate: Can Perl string interpolation perform any expression evaluation? I know I can print a variable inside of a string in quotations like: print "my variable foo = $foo" Is there a way to do the same for methods? Something like: print "my method evaluates to $some_obj->someMethod()" ...

Is the Perl Goatse 'Secret Operator' efficient?

The "goatse operator" or the =()= idiom in Perl causes an expression to be evaluated in list context. An example is: my $str = "5 and 4 and a 3 and 2 1 BLAST OFF!!!"; my $count =()= $str =~ /\d/g; # 5 matches... print "There are $count numbers in your countdown...\n\n"; As I interprete the use, this is what happens: $str =~ /\d/g ...

How can I round off the elements in a Perl array to just two decimal places?

I have an array with a few elements: MSN = 34.3433423432434% Chrome = 12.4343434353534% Gtalk = 32.23233543543532% ... And I'm passing this array as y-axis labels to use with a module called GD::Graph. The problem I am facing right now, is that the number are so big on the graph that they overlap with the adjacent entry...

ClearQuest Perl : how to clear a list of values? SetFieldValue doesn't work on lists

Hey! New to Perl and new to ClearQuest Perl API both. I am trying to clear some values from a CQ form. I am able to clear values by simply setting the value to "" but it doesn't work on lists. Any idea how this can be done? # following doesn't work on lists. What to do? $entity->SetFieldValue("Foo_List", ""); # following works ...

Looking for a way to scrape urls from a page and output it to a text file

I am looking for a way to scrape URLS from a web page and output it to a text file. E.g if a page contains multiple http://example.com/article I want to grab both these URLS and output it to a text file. ...

PERL + Make + system()

Aite, I met a weird thing today with PERL. Couldn't understand: file a.pl: $x = $ENV{$x}."123"; $x = "weird"; system("b.out"); #there is no such $ENV{$x}=.... in this file. It is executed directly from "make" #and "make" also doesn't have any lines which set environment variables..... However, b.out somehow can read $x value as an en...