This guy posted on a number of forums and already has a solution, he will not be coming back here to read your response.
PoovenM commented: Thank you for the assistance :) +2
This guy posted on a number of forums and already has a solution, he will not be coming back here to read your response.
Do you have some perl code you need help with?
to quote myself:
post some sample input data and desired output data.
post some sample input data and desired output data.
If you want to continue with awk you should take this discussion to an awk forum.
Perl has very similar command line syntax to awk and could be done as a command line/one-liner if you really wanted to do that. one-liners are good for very targeted tasks, but not so good when you have more complex programming problems.
Your problem is right about in the middle of being a simple task and a more complicated one better suited to a script.
I assume this is what you are actually trying to do:
my %stuff= ();
open (OUT, "data.txt") || die "Can't open the data file";
while (my $line = <OUT>) {
chomp $line;
my ($short,$place) = split(/\|/,$line);
$stuff{$short} = $place;
}
close OUT;
foreach my $key (keys %stuff) {
print "$key = $stuff{$key}\n";
}
You seem to have skipped the basics of perl. The biggest problem is using single-quotes around your scalar variables, which will not interpolate them but treat them as literal strings. You almost never quote a lone scalar variable anyway. Assuming $data[0] and $data[1] are properly defined:
my %stuff = ();
foreach my $i ($data[0], $data[1]){
chomp($i);
my ($short,$place) = split(/\|/,$i);
$stuff{$short} = $place;
}
Be happy to help you if you have put any effort into solving the problem. BUt I will not just write a script for you based on your requirements, this is not a script writing or do-my-homework service.
sub dec2mac {
return sprintf("%s:%s:%s:%s",unpack("A2A2A2A2",sprintf("%08X", $_[0])));
}
Sorry, I have no experience using threads. If you get no further replies here ask on www.perlmonks.com
"pack" and "unpack" have lots of templates used for this type of conversion of one thing into another thing. I don't know if they can do what you want, but that is a starting place anyway.
Fran123,
Now you're just being obnoxious. I assume you will now be banned and I won't miss you. Too bad you couldn't just come here to try and help people instead of putting in a plug for your website. Your above post has been reported.
There are those people, but they are on all perl forums, not just this one. I post on about 10 perl forums, but only three or four are very active, the rest are like this one, an occasional question. But they all get requests that seem to be people wanting their work done for them, and some students too.
Some people on this forum are like that, but I am not a student nor am I from a second-world country, although it is debateable since the USA is going down the tubes pretty fast.
Open an editor and start writing code and testing the results is how you start. School work?
Personally I think the OP has been given more than enough information to figure this out, all they have to do is try some of the suggestions and mess around a bit with some code to fine tune it to their needs.
if ($word =~ /RNA\s+?-?\s+?binding\s+proteins?/i) {
do somethihng
}
if ($word =~ /RNA[ -]?binding protein/) {
do somethihng
}
if (/RNA[ -]?binding protein/) {
do somethihng
}
? is a quantifier which means zero or one, its the same as:
if (/RNA[ -]{0,1}binding protein/) {
do somethihng
}
Look up "quantifiers" in a regular expression tutorial.
I have no idea if using perl will ultimately prove to be faster or not. You will just have to try it and see.
I would read the file line by line instead of trying to make a single regexp that tries to do too much.
while(<>){
if (/^([a-zA-Z]{0,2}\d+)/) {
my $id = $1;
# now get the title/source/text in this block
# and write to a new file
}
}
Both of my files are huge
How big are they?
You install the module or use the lib pragma to run the module from @INC without actually installing it.
I don't know how you install modules on a MAC, maybe you use the CPAN shell. You can read the "lib" pragmas documentation online:
Yep, there is a limit to the amount of GET data. If my memeory servers my well, it's 255 bytes (characters). I'm not sure if this is before or after url encoding.
With that amount of data, I suggest going either to a form with POST data, or writing some of if off to a session.
I think you posted in the wrong thread.
Well, if you mean the action attribute of the form tag, thats not the way to go about it. One way is to include a hidden form field with the name of the subroutine you want to run:
<input type=hidden name=action value=new>
after parsing the form data check the value of the "action" paramater:
if ($form{'action'} eq 'new') {&new;}
elsif ($form{'action'} eq 'reg') { ® }
elsif ($form{'action'} eq 'procreg') { &procreg; }
elsif ($form{'action'} eq 'creg') { &creg; }
elsif ($form{'action'} eq 'proccreg') { &proccreg; }
elsif ($form{'action'} eq 'forgot') { &forgot; }
elsif ($form{'action'} eq 'sendinfo') { &forgot; }
else { &enter;}
Why scripts work on one server and not another is difficult to impossible know why unless you know everything about what software is installed, what operating system the server uses, and etc.
But did you try removing the -nph option or not? That is mainly, if not specifically, for IIS servers, not Unix or Linux servers. -nph prints the headers in a different way, but I don't know the details, just try removing it.
Yes, it's working with that simple script.
Do you mean the standard -nph cause the problem?
Try removing the -nph option and see if that clears up the problem. If you don't know what the -nph option does, chances are you don't need to use it.
Are you sure you want or need to use the -nph option?
try this:
#!/usr/bin/perl
print "Content-type: text/html\n\nHello World";
see if that simple script will work.
Well, you have this line in the code you posted:
my $dbh = DBI->connect("dbi:mysql:db_hhh:localhost", "hhh", "123456",{RaiseError=>1, AutoCommit=>1, ShowErrorStatement=>1}) or print "failed to connect to database\n";
if the "or" condition is evaluated then the script will error out because you have not printed an HTTP header before trying to print "failed to connect to database\n";.
Print the HTTP header before the above line of code runs.
make sure to upload the perl script in ASCII text mode (see you ftp applications help files if necessary) and that the permissions are set if necessary, normally a perl script is chmod 755, you can also do that with your ftp application.
add this line anywhere in the script and see if it returns more specifc information about the error:
use CGI::Carp qw/fatalsToBrowser/;
Yes you can. It does not matter if the page is static or dynamic.
if (some condition) {
do_this()
}
You can also make a hash table where the values of the hash keys are references to subroutines.
Ask for references, read comments from previous customers, have their work reviewed by a third party. It would still be possible to be fooled but many of the hire-a-programmer sites do a good job of hooking up customers with good programmers.
They can always try and hack/crack the script to see what happens under various conditions, which is the acid test of any CGI script.
But that would be sensible and prevent unnecessary effort. This is the Internet, mister! We don't hold with that sort of behavior!
LOL..... :icon_lol:
You should use one script to handle the entire process. But, writing CGI scripts is not a good idea for a person that seems to not have any experience and probably does not understand even the basics of writing secure CGI scripts. I suggest you hire a programmer, one that can demonstrate that they can write a secure CGI script. A script like this should not cost very much. You can post jobs on many websites and take bids from programmers.
All he has to do is look in the Snippets section of this website, go to the perl section and read the "Script to Remove duplicate lines" snippet.
42.... been a long time since I read the book. ;)
The answer is 49.
I nominate you for forum cross-poster of the month award. Thats three perl forums so far I have seen this same question posted on.
I'm pretty sure its matlab, of which I know nothing. So I suggest you find a matlab forum or mailing list.
the code you posted is not perl, I am not sure after reading your post if you know that or not.
You can read from and write to the same file at once, but it's difficult.
Actually it is very simple, you can use the Tie::File module to read/write to the same file or perls inplace editor, which would be my choice since it is way more effcient than Tie::File, but Tie::File has an extremely easy interface.
I'm sorry but I can not help with issues of running or installing strawberryperl. I have installed it on a couple of of Windows PCs (XP and 2000) and it ran fine for me.
Maybe one of the resources listed on the strawberryperl website can assist you:
replace these lines:
#create page
print <<endHtml;
replace with:
#create page
print header;
print <<endHtml;
"header" is a function of the CGI modules ":standard" functions and will print the http header which is required before printing anything else to the browser. I could have sworn I already told you that on another forum but maybe I am confused.
This is a more drastic option, you can try www.strawberryperl.com which is a windows port of perl that uses the standard CPAN interface.
You can add repositories but there are a lot of modules that have never been ported to PPM. You can download modules and put them in a folder of your choice and use the lib pragma to include the folders in @INC. Sometimes this is difficult if there are a lot of modules and sub modules but it is doable. Or maybe someone can help with installing CPAN modules into your activeperl libraries, or ask on www.perlmonks.com.
Some PPM repositories that are good:
http://theoryx5.uwinnipeg.ca/ppms
http://www.bribes.org/perl/ppm/
You should not use numbered scalar variables in your perl programs, $1 and $2 and etc are used internally by perl for pattern memory and are read only. If you have meta characters in your array elements just use the \Q option to escape them:
$foo =~ /\Q$bar/;
stuff like ** will be interpreted literally, but $ and @ will still be treated like a variable and interpolated.
looks like you are on Windows, so I assume you are using activeperl. For that you use the PPM application to install modules. Read the activeperl documentation for instructions on using PPM. There is no compling involved.
Its not strange at all. What is strange is your post, it makes no sense.
In addition to the characters you posted the character class will also match 0-9 which is part of the \w character list:
a-zA-Z0-9_
If you don't want 0-9 you have to do this:
[a-zA-Z_\s]