perl

Perl modulo operator question

Why does the first example print a wrong result ? perl -le 'print $x = 100*1.15 % 5' 4 perl -le 'print $x = 1000*1.15 % 5' 0 ...

Perl RegEx to find the portion of the email address before the @

Hi, I have this below issue in Perl.I have a file in which I get list of emails as input. I would like to parse the string before '@' of all email addresses. (Later I will store all the string before @ in an array) For eg. in : [email protected], i would like to parse the email address and extract abcdefgh. My intention is to get o...

perl smtp datasend

I'm testing a program that I'm writing in perl to send automated emails by sending them to myself first and I am noticing that all the carriage returns and tabs (\n and \t) that I am putting in the emails are turning up in outlook as spaces when I read the emails. Any idea what could be going on here? ...

Return perl array to MATLAB

Is there a way to return a perl array to MATLAB? Or do I just have to return a string and parse it? I'm using a call from MATLAB to a perl script to interface with a MySQL database. After I get the results of a query, I want to pass it back to MATLAB. EDIT: I'm using a modified version of perl.m to call the perl script. It calls the ver...

Securely storing user data in MySQL?

Hello, I'm creating a service that will gather user data such as username, name, email, login password. How do I securely store this data? One thing I was thinking is store it encrypted in the DB so that if anyone gets access to the DB they won't be able to use the data. But that arises two issues - #1 - much much slower search of the ...

How do i export a function named 'import' from a module in Perl?

I've written a special import function that will be used in a few places and I'd like to be able to just go "use ImportRenamer;" in those modules and have them use the import gained from ImportRenamer henceforth. How would i go about that? Edit: In other words: How do i import 'import' without running it? ...

Why am I getting an exception when I try to set the value of a cell in Excel using Perl's Win32::OLE?

I am getting the error Win32::OLE<0.1709> error 0x80020009: "Exception occurred" in PROPERTYPUT "Value" at line 109. The code in is Perl. foreach my $ref_array1 (@$array1) { # loop through the array foreach my $col1 (@$ref_array1) { foreach my $ref_array2 (@$array2) { # loop through the array foreach my $col2 ...

Computing number of arrays containing an element in perl

I think I've just been looking at this too long. I have some data that looks like this: @a = ( { name => 'ethan', depth => 0 }, { name => 'victoria', depth => 1 }, { name => 'stephen', depth => 2 }, { name => 'christopher', depth => 3 }, { name => 'isabella', depth => 2 }, { name => 'ethan', depth => 3 }, { ...

One liner nested hash creation in ruby? (I come from perl)

I am a perl person and I have made hashes like this for awhile: my %date; #Assume the scalars are called with 'my' earlier $date{$month}{$day}{$hours}{$min}{$sec}++ Now I am learning ruby and I have so far found that using this tree is the way to do many keys and a value. Is there any way to use the simple format that I use with pe...

SVN not seeing changes

Hi all, I just ran a perl script to replace all occurances of one word for another for my whole project. ie: perl -e "s/OLD/NEW/g;" -pi $(find ./ -type f) I want to commit these changes to subversion, but when i run "svn status", none of the modified files appear on the list. The same thing occurs in TortoiseSVN using the "Check fo...

perl regular expression hash with /e

Hi, I am looking to substitute hash value with perl regular expression /e option. The following code is not working for me. #!/usr/bin/perl %hash=( 1 => "aa", 2 => "bb", 3 => "cc" ); $_="name,3"; s/^(name,(\d+).*)/$2,$hash{$1}/e; print "$_\n"; exit 0; I am expecting output like this: name,3,cc How can I make this work? Thank...

release memory for multi-level hash

Assume I have a muti-level hash: $class->{'key1'}->{'key2'}->{$key3}->{'string'}->{$key5}, where $class->{'key1'}->{'key2'}->{$key3}->{'string'}->{$key5} equals to some integer number. $key3 can be class name like "music", "english"... $key5 can be student name like "mary", "luke"... Will the following operation release...

How do I check for duplicate column values in the table before I insert them with Perl?

I am reading a file which contains a record in each line. I am extracting the contents of the file and inserting it as column values into a table. The problem I face is, suppose if i insert a record into a table after reading from the file, I want to remove the duplicate fields. For example: NAME age time Tom 21 10:30 Tom 21 12:21...

perl + identify if param is empty value from ARG

Hi all, when I run the following script.pl script with no arguments: ./script.pl I do not get the message No arg. Why? How to identify if $param is a null value or empty value, same as [ -z from ksh? #!/usr/bin/perl my $param = $ARGV[0]; if ($param = "") { print No arg; } else { print arg: $param; } ...

Prevent to submit form while checking for Current Password?

Hi, I use CGI::Ajax to check password on blur event of Password textbox field and disabled the submit button (by defualt submit button is active) if current password is wrong using jquery $('#submit_btn').attr('disabled'); It's working fine for me. But when user enter wrong password and click on Submit button directly without using ta...

perl + @ARGV + print syntax

hi How to print the number of arguments from @ARGV according to the following script why its important to print like print q{don't have parameters}; And not as print "don't have parameters"; ?? lidia #!/usr/bin/perl if (@ARGV) { print ...... } else { print q{don't have parameters}; } ...

printing elements in a nice format

Hi, I have a simple, general question regarding a real small issue that bothers me: I'm printing a list of elements on the fly, so I don't have prior knowledge about the number of printed elements. I want a simple format where the elements are separated by a comma (elem1, elem2...) or something similar. Now, if I use a simple loop like: ...

How do I update records only if I find a duplicate or otherwise insert data?

In the code below there is a hash which contains records with fields like name, pid, type and time1. pid and name are repetitive fields which contain duplicates. I duplicate found update the fields which need modification else insert, here name and pid have duplicates (repetitive fields). The rest are unique. Also I have a unique field...

Perl RegEx: Limiting the pattern to only the first occurrence of a character

I am trying to extract the content of a date element from many ill-formed sgml documents. For instance, the document can contain a simple date element like <DATE>4th July 1936</DATE> or <DATE blaAttrib="89787adjd98d9">4th July 1936</DATE> but can also as hairy as: <DATE blaAttrib="89787adjd98d9">4th July 1936 <EM>spanned across mu...

How do I find a comment with PPI and then insert code before it?

I'm trying to find the comment # VERSION in a perl source file. I then want to insert the version before the comment (or in place of doesn't matter). Could anyone tell me the right way to do this with PPI? before use strict; use warnings; package My::Package; # VERSION ... after use strict; use warnings; package My::Package; our $VE...