Re: Substitution Problem
can anyone give me some help on a perl program to change a file of mine. The string is: $_ = from ''alam' (481) or possibly (in the sense of dumbness); solitary; Ulam, the (6155) name of two Soldiers;--Ulam. Where each line is $_ I'm trying to substitute a hyperlink for each NUMBER that is in parenthesis only, while not touching the words in parenthesis or any other numbers. For example, I want to change (481) in the line above to (href=mypage.php?481481/a) and (6155) to (href=mypage.php?61556155/a) and any others without changing anything in (in the sense of dumbness). Doing the same thing with each line in a file. Should I use a substitution? Can anyone show me some code to accomplish this. Thanks.
Re: Substitution Problem
In a message dated 6/28/2010 7:49:47 P.M. Eastern Daylight Time, jwkr...@shaw.ca writes: jimston...@aol.com wrote: can anyone give me some help on a perl program to change a file of mine. The string is: $_ = from ''alam' (481) or possibly (in the sense of dumbness); solitary; Ulam, the (6155) name of two Soldiers;--Ulam. Where each line is $_ I'm trying to substitute a hyperlink for each NUMBER that is in parenthesis only, while not touching the words in parenthesis or any other numbers. For example, I want to change (481) in the line above to (href=mypage.php?481481 ) and (6155) to (href=mypage.php?61556155) and any others without changing anything in (in the sense of dumbness). s/\((\d+)\)/(_$1_ (mip://050adf60/mypage.php?$1) )/g; Excellent! Works perfectly. Thank you so much!
Help With Filtering Messages
I know there is probably a simple solution for this, but can anyone help me with code to filter out messages with extended characters like these: àïåëüñèí êàïèëêà òàáëåòêè ïåðåêèñü òåëåôîí òåòðàäè êàðàíäàøè îá¸ðòêè îò êàíôåò êîðîáêà îò òåëåôîíà âàòà âàçà äèñêè êíèãè è òåòðàäè È åùå êó÷à áóìàæåê è âñÿêîãî õëàìà Just something to dump any messages with these characters. Is there a simple way? **A Good Credit Score is 700 or Above. See yours in just 2 easy steps! (http://pr.atwola.com/promoclk/10075x1218550342x1201216770/aol?redir=http://www.freecreditreport.com/pm/default.aspx?sc=668072%26hmpgID=62%26bcd=fe bemailfooterNO62)
Pattern Matching
Hi, I am a beginner in perl and am having a dickens of a time trying to identify this pattern in messages. [URL Here is what I have: if ($FORM{'message} =~ /\[URL/ig) { #do something; } Where $FORM('message') is a messaage that includes many lines and [url=http://www.mywebspace.com[/url]. But this doesn't result in true even though I know the message contains the string [url. Can anyone tell me what could be the problem? Or perhaps a better way to identify a messages with the [url anywhere in it. Thanks for any help.
Re: Pattern Matching
In a message dated 7/23/2006 9:39:34 A.M. Pacific Standard Time, [EMAIL PROTECTED] writes: [EMAIL PROTECTED] wrote: Hi, I am a beginner in perl and am having a dickens of a time trying to identify this pattern in messages. [URL Here is what I have: if ($FORM{'message} =~ /\[URL/ig) { #do something; } Where $FORM('message') is a messaage that includes many lines and [url=http://www.mywebspace.com[/url]. But this doesn't result in true even though I know the message contains the string [url. Can anyone tell me what could be the problem? Or perhaps a better way to identify a messages with the [url anywhere in it. Thanks for any help. works for me! I assume missing ' is just a typo else you would get compile error [EMAIL PROTECTED] re]$ cat url.pl #! /usr/bin/perl use strict; use warnings; my %FORM; $FORM{'message'} = Where \$FORM('message') is a messaage that includes many lines and [url=http://www.mywebspace.com[/url]. But this doesn't result in true even though I know the message contains the string [url. Can anyone tell me what could be the problem? Or perhaps a better way to identify a messages with the [url anywhere in it. Thanks for any help.; This works as long as the escaped bracket is not included. As soon as I include the \[ it no longer works? No longer returns true. There has to be an answer to this? I don't get it? Could it be attempting to match the \ as well?
Re: Checking if URL is on a list.
In a message dated 8/10/04 4:15:12 PM Eastern Daylight Time, Jimstone77 writes: I am not entirely sure I follow but does this do it? if ($siteurl2 =~ /^(?:www.)?$FORM{'siteurl'}\/?$/) { print Matched; } Aka optionally 'www.' followed by the submitted URL, with an optional trailing slash. If not come back and someone will get you sorted Ok, maybe I wasn't clear. What I want to do is check a URL against urls in a list, so that all six forms of the url will match so duplicates won't be indexed. http:/www.mysite.com/ http:/www.mysite.com http:/mysite.com/ http:/mysite.com www.mysite.com/ www.mysite.com So that the FORM{'siteurl'} will match with any of these ways a URL may have been listed. And maybe even just as mysite.com. Without all the || (or) functions in my example. Is there a simple way to do this?
Checking if URL is on a list.
I know there is a much simpler way to do this. What this does is check a URL written with and without www. or trailing / against a list of urls that (one at a time) are placed in $siteurl2. $FORM{'siteurl'} is the site url being submitted. $alternativeurl is $FORM{'siteurl'} without the www. if with. $xalternatives is $FORM{'siteurl'} with the www. if without. This works ok it seems, but it's horrible code. There must be a better way to write this. Any help will be appreciated. if (($FORM{'siteurl'} =~ /$siteurl2$/) || ($FORM{'siteurl'} =~ /$siteurl2\/$/) || ($alternativeurl =~ /$siteurl2$/) || ($alternativeurl =~ /$siteurl2\/$/) || ($xalternatives =~ /$siteurl2$/) || ($xalternatives =~ /$siteurl2\/$/)) { print Found 1 \n; }
Determining Odd and Even Numbers
Does anyone know a simple way to determine if a number is odd or even? For example 220 would come out even while 221 would come out as an odd number.
Re: Determining Odd and Even Numbers
Thanks everyone!
Windows Perl Environment
Is there any program that allows one to write Perl scripts and and then test them in a windows environment without using a DOS window, and actually have me see the program run before I upload it to a server, rather than just testing if the script runs without errors? Anyone know what I mean and know of any such program?
Counting characters in a thread
$string = a%3A2%3A%7Bi%3A0%3Bs%3A3%3A%22489%22%3Bi%3A1%3Bs%3A32%3A%22a85a44c1881523798bc155a5369e1226%22%3B%7D How would I empty $string if it contained more than ten % characters? In other words $string = a%3A2%3A%7Bi%3A0%3Bs%3A3%3A%22489%22%3Bi%3A1%3Bs%3A32%3A%22a85a44c1881523798bc155a5369e1226%22%3B%7D Would be emptied, while $string = a%3A2%3A%7Bi%3A0%3Bs%3A3%3A%22489%22 would not.
Strings with extended characters
Is there a simple way to reject any string that has extended characters in it? In other words, only accept the 88 (I think it's 88) regular keyboard characters and numbers. I can't find a simple way to do this.
Incrementing count
I'm sorry, the previous subject should have been changed. My apologies. while (FILE) { $counter++; } I know this is probably simple, but how would I increment by 20? In other words, $counter would increment 1 time for every twenty lines of the file? Any help would be appreciated.
Re: interpolated strings
while (FILE) { $counter++; } I know this is probably simple, but how would I increment by 20? In other words, $counter would increment 1 time for every twenty lines of the file? Any help would be appreciated.
Re: Counting (easy!)
I have a list of email addresses in a text file one to a line. How would I seach for a particular email address? $email = [EMAIL PROTECTED]; while FILE { if ($email eq $_) { $OK = 1; } } It seems the @ symbol somehow doesn't work in this search. What would be a better (or right) way to do this? thanks in advance.
Corrupted Data
I'm having problems with corrupted data about every month or so. The problem seems to be that the New file sometimes writes only about half the old file. I was under the impression that flock would prevent the data from being corrupted. Can anyone tel me what I am doing wrong, and what I should be doing instead? open(OLD,$old) or die Can't Open File: $!; flock OLD, 2; open(NEW,$new) or die Can't Open File: $!; flock NEW, 2; while (OLD) { if ($_ =~ /NO_EMAIL/) { $count++; } else { print NEW $_; } } close(NEW) or die Can't Close File: $!; close(OLD) or die Can't Close Old: $!; Is there something inherently wrong with doing it this way?
Re: Corrupted Data
In a message dated 10/30/03 10:35:08 AM Eastern Standard Time, [EMAIL PROTECTED] writes: ] Why don't you post the actual code since this obviously isn't it... $old = oldfile.txt; $new = newfile.txt; open(OLD,$old) or die Can't Open File: $!; flock OLD, 2; open(NEW,$new) or die Can't Open File: $!; flock NEW, 2; while (OLD) { if ($_ =~ /NO_EMAIL/) { $count++; } else { print NEW $_; } } close(NEW) or die Can't Close File: $!; close(OLD) or die Can't Close Old: $!; rename($old,$new); Is there something inherently wrong with doing it this way?
Re: Corrupted Data
In a message dated 10/30/03 12:04:07 PM Eastern Standard Time, [EMAIL PROTECTED] writes: Yes there is. (Apart from the typo on the open(NEW,...) line.) The problem is that things could happened between you close the old file and rename the new one. And even more likely there can be a process that already has the old file open. So even if you rename the files, the process still has the old one. And as soon as you unlock it, the other process starts reading ... the old data. You HAVE to use a separate log file! Eg. like this (I'm sure someone will be happy to correct me if I screw up) sysopen(FH, file.lock, O_WRONLY|O_EXCL|O_CREAT) or die can't open file.lock: $!; open(OLD,$old) or die Can't Open File: $!; open(NEW,$new) or die Can't Open File: $!; while (OLD) { if ($_ =~ /NO_EMAIL/) { $count++; } else { print NEW $_; } } close(NEW) or die Can't Close File: $!; close(OLD) or die Can't Close Old: $!; unlink $old or die cannot unlink the old file\n; rename($new = $old) or die cannot rename\n; close FH; unlink file.lock; or open(LCK, file.lock) or die can't open file.lock: $!; # so someone else has it opened as well, who cares flock(LCK, LOCK_EX) or die can't lock the lock: $!; # I am the only one who can have it locked though open(OLD,$old) or die Can't Open File: $!; open(NEW,$new) or die Can't Open File: $!; while (OLD) { if ($_ =~ /NO_EMAIL/) { $count++; } else { print NEW $_; } } close(NEW) or die Can't Close File: $!; close(OLD) or die Can't Close Old: $!; unlink $old or die cannot unlink the old file\n; rename($new = $old) or die cannot rename\n; close LCK; The second seems a little safer to me (the system will remove the LOCK (not the lock file, just the lock) if the script dies). Jenda A Thousand Thanks! As a real beginner I appreciate your taking the time to help me find a solution to this problem, and explaining the possible reasons. I think I now have a better grasp of what's going on and why. Again, many Thanks for your patience!
Determining size of gif or jpg file
I am writing a program to allow pictures displayed, but I want to limit the size of the images. How would I determine the size of image files using perl?
Re: getting the IP address of a visitor to a site
In a message dated 9/11/03 6:10:06 PM Eastern Daylight Time, [EMAIL PROTECTED] writes: On Thu, 11 Sep 2003 12:46:24 + Anadi Taylor [EMAIL PROTECTED] wrote: I am writting a hit counter and would like to get the IP address of a visitor to my site, can anyone point me in the right direction please. You might look at Enviroment variables, partcicularly $IP_Address = $ENV{REMOTE_HOST};
Ring Bell
Is there any way in PERL to ring a Bell or make some sound in a script. For example, to let you know when a task is completed. Any help would be appreciated.
Retrieving word and sourounding text
$word = seminary; I am trying to retrieve a word, and the surrounding text in a file. For example, read through a file for $word, and when matched, place in a variable the matching word, along with the 10 words preceding it and trailing it, and have it work over multiple lines. Is there an effective way to do this in Perl? i.e., in the paragraph above, if I searched for the word along match would contain what is written below. Can anyone help me with this? Thanks. $match = and when matched, place in a variable the matching word, along with the 10 words preceding it and trailing it, and;
Grabbing from a string
How can I grabb the browser name Opera and the version number from a string, when it's very important that I get the whole version number. For example: Windows XP) Opera 6.05 [en] or MSIE 6.0; MSIE 5.5; Windows NT 5.1) Opera 7.0 [en] Can anyone show me the best way to place Opera and the whole version (i.e., Opera 6.05 or any other version number) in a string variable. I thought maybe a regex would work, but as a newbe I'm just spinning my wheels. Thanks.
Re: Grabbing from a String
In a message dated 3/29/03 7:16:57 AM Eastern Standard Time, [EMAIL PROTECTED] writes: This returns 4. I need the Opera 7.0 to be in $browser. my $string = 'Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.1) Opera 7.0 [en]'; my ($browser) = $string =~ /(\w+\s*[\d.]+)(?!.*\d)/i; print $browser; this works if the version numbers ar the last digits on the line But it doesn't solve my problem. This returns MSIE 5.5 not Opera 7.0 on the example above. Still looking for an answer.
Split Problem
I'm having a problem splitting a variable and need some help. What I have is some variables with a name, and then information in parens. A couple examples: $data = David (man from uncle); $data = John Doe (The boy down the hall); What I want to do is split $data into two string variables, one holding the $name, and the other holding all the $info that is within the parens. How would I do this? Thanks for any help.
Re: screen size question
In a message dated 3/27/03 5:41:14 PM Eastern Standard Time, [EMAIL PROTECTED] writes: perl -e ' @x = qx(stty -a); @y = split(/\s/, $x[1]); $y[2] =~ s/;//; print screen size is $y[2] x $y[5] ' stty -a works on every *nix system I know. Some systems have 'stty -size' to help with exactly what you are asking. Hope that helps. Thanks a Lot! I didn't think that question would ever get answered. Much appreciated.
Reading Directories
Does anyone know how to read a directory in perl, and make a list of all the files therein, and also of any sub directories and their files?
Re: Printing epoch time
can anyone show me how I would get the screen resolution with perl in a unix environment?