196 Posted Topics
Re: Hi, Since you know hash 2 keys relate with hash 1 values, you can just say, print hash 1 key, when hash 1 value equals hash 2 key. Bingo!!! You are done. Like so: use warnings; use strict; my %hash1 = ( a => 1, b => 2, c => … | |
Re: Hello yksrmc, This can easily be done by going through your data a line at a time. Since it's only the last number that is changing there is no need comparing it with the pervious figure before it. Just take the number you wanted and check the condition you specify, … | |
Re: Hello yksrmc, This can easily be done by going through your data a line at a time. Since it's only the last number that is changing there is no need comparing it with the pervious figure before it. Just take the number you wanted and check the condition you specify, … | |
I wanted a graphical representation of the listing of my files and folders from the command line interface, just like what the CLI **tree** would give on linux system, I really don't like how the same command is displayed on windows. So, I called on ma 'Cherie' Perl do it … | |
Re: Hi, You can simlpily do like so: use warnings; use strict; my $str = 'cat/dog/cat'; $str=~s{dog/cat$}{tiger/deer}; print $str; #cat/tiger/deer #OR You can run the following from Command Line Interface: `perl -we '$_=q[cat/dog/cat];s{cat/dog/cat$}{print qq[cat/tiger/deer\n]}e;'` You don't need the modifier `g`. If you are reading the string from a file you might … | |
Re: You didn't show how you use the module Win32::OLE, so really one might not know how and where you are having issues with your code. There are several part of the code you need to upgrade. Like, why use 2 while loop? | |
Re: Please check this Perl module [WWW::Mechanize::Firefox](https://metacpan.org/module/WWW::Mechanize::Firefox) from METACPAN, it should help, with this kind of stuff you want to do. | |
I really got bored and tired of trying to find or remember some codes usage in so many files saved on my system, when it was needed. So, I called 'Monsieur' perl for help, hacking together some codes which works great for me and solve my problem of boredom. You … | |
Re: Hi rajesrmbioinfo, I know there are more than one way to do it in Perl, but so many ways are not efficient and effective. Am glad you have your coding working fine, but there are some things I believe you should also put in place. 1. Your open function should … | |
Re: Hi, You can do this: #!/usr/bin/perl use warnings; use strict; my %count_variable_converted; chomp( my $title = <DATA> ); print $title,$/; while (<DATA>) { next if /^$/; s/\s$//g; my @data = split /\s+?/, $_, 5; $count_variable_converted{'A/T'}{'A/A'}++ if ( $data[3] eq 'A/T' and $data[4] eq 'A/A' ); $count_variable_converted{'G/C'}{'C/C'}++ if ( $data[3] eq … | |
Re: Hi Tony75, Could you run your compile program on system on which perl is not installed? If Yes, I think you are cool. Sorry, not on Window OS presently [ I suppose that program will run on one], so I can't say authoritatively. | |
Re: Hi sandeepbajjuri, It seem to me you are looking for Perl function backtick written as `` or `qx`. You might also want to look at Perl function `system`. From within your perl script you just do like so: `system("generator.exe");` your code then runs as if you are on a CLI. … | |
Re: Hi tony75, To parse HTML in Perl, you might have to know how to use some Perl modules. HTML being what it is, can really be best parsed not with regex. That been said, there are a number of module on [CPAN](http://www.cpan.org) and [meta::cpan](http://www.metacpan.org) which can be used to parse … | |
Re: Hi tony75, There are more than one way to achieve your aim. Of course, using the function `opendir` and reading all your filename like you did should work, but why not use one of the CORE module to go through the file for you save the filename and other requirement … | |
Re: Hi hero19760, >Can you please help me No! Because, I don't know what your text file looks like. Moreover, in Perl Programming there is more than one way to do a thing. So, show how your data look likes or give an idea of what it is, then we can … | |
Re: Hi hero19760, We can't magic know how the webpage you wanted to parse look like do we? Moreover, what have to tried on your own that you want a help for? I believe this is how to get help anywhere as soon as possible. Hope this helps | |
Re: Hi rajesh9042, There are several things not right with your script namely: 1. Please start your script with use warnings and use strict pragmas, though I know many people may not like these. But believe me, those are your best friend programming in Perl, 2. What do you have in … | |
| |
Re: Hi tony75, 1.What error message are you getting. 2.Check your filehandle "IN" you used. You can't be reading FROM and writing TO the same filehandle, like you are doing. 3.Also use a 3-arugment for open function. like open my $fh,'<',$file_to_read or die "can't open file: $!"; while(<$fh>){ ... } close … | |
Re: Hi vivek.vivek, Using hash in perl takes care of all issues you have in this your post. Please, check the solution below and feel free to ask any question. #!/usr/bin/perl use warnings; use strict; my %seen; while (<DATA>) { chomp; my @data_filter = split; if ( defined $data_filter[2] and !exists … | |
Re: Hi FelineHazard: The following modules from [CPAN](http://www.cpan.org) could be of help: [URI](http://search.cpan.org/~gaas/URI-1.60/URI.pm) with [URI::Escape](http://search.cpan.org/~gaas/URI-1.60/URI/Escape.pm). Or [Data::Validate::URI](http://search.cpan.org/~sonnen/Data-Validate-URI/lib/Data/Validate/URI.pm) However, I could only have one question; why validate if the URL doesn't exists? Hope this helps. Enjoy. | |
Re: Hi voidyman, There is a better way of writing the perl code you showned. 1. Use a 3 agrument open function like `open my $fh,'<',$filename or die "can't open file: $!";` 2. Don't use a bareword for filehandles like FILE_OUT etc Instead use a lexical filehandles as showned in (1.) … | |
Re: Hi mshefa, I will advise that you use 3 argument open function as demonstrated below. Moreover, please check the proper usage of split function... The following code show how to get desired result: #!/usr/bin/perl use warnings; use strict; my $parameter = qr/\.|"|,/; my @words; open my $fh, '<', "test.txt" or … | |
Re: Hi ashiiiish, Consider using these modules from [CPAN](www.cpan.org) namely: 1. Text::CSV_XS 2. Spreadsheet::WriteExcel From the directory read each of the CSV using Text::CSV_XS or Text::CSV, then write to a new Excel Sheet created by Spreadsheet::WriteExcel. Check examples these modules except you have sample of what to share here. Hope this … | |
Re: Hi Taywin, >If there are duplicated lines in file2, I am not sure it would print all the duplicated line numbers? Despite, its functionality may already satisfy what the OP wants. Nice observation, and that was my initial thought too until I read again the OP's last comments * It … | |
Re: Hi wickedxter, Though your script compile, but will produce no output, because there is no match in your regex. Since each of the value read into the array variable `@Blocked_Words` has a trailing "\n". check this using `use re qw(debug);` in your script. However, doing `chomp(my @Blocked_Words = <DATA>);` resolves … | |
Re: Hi erezz, You can achieve what you wanted using perl inbuilt functions. Atleast that is one way to go about it. For example, if your file has a fixed length that the you posted above, one can do like so: use warnings; use strict; use constant ZERO => 0; use … | |
Re: Hi rogerg, This problem could be easily solved using map and grep in Perl like so: use warnings; use strict; my $splitter = qr/[^a-zA-Zà âäéèêëîïôöùûüç]/; # split on the following my %word_freq; ## hash variable my @chains = ( "just trying to figure this out,", "cant figure how to do it…", … | |
Re: Hi, You didn't tell us that this was also cross-posted in perlmonks [Merge columns from two different files](http://www.perlmonks.org/?node_id=1008972) and stackoverflow. | |
Re: Hi nakshi, Here is one. #!/usr/bin/perl use warnings; use strict; my @data_array; push @data_array, join " " => @{ [split] }[ 4, 1 ] while <DATA>; local $" = "\n"; print "@data_array[0,$#data_array]"; __DATA__ HETATM 7749 C1 NFG A1001 -31.772 -7.604 -23.847 0.80 61.71 C HETATM 7750 O1 NFG A1001 -30.806 … | |
Re: hello dsplayer14, First of, Line 23, is NOT just a convinience measure. The chomp function removes the trailing "\n" from your input from STDIN. Commet out line 23, and see the error message, you get. Secondly, it would be goood if your script is kept in a loop, like a … | |
Re: Hi laksraju, Please could you show what you have done so far. The area of the code where you are having problems. Writing the code for you would not help you in the long run. Secondly,you might look into the archieve of this forum. This kind of problem has been … | |
Re: Hi vassi, Please show some example of what you have be able to do so far. With input, codes and desire results and possibly error messages. So that we can help. | |
Re: Hi James 79, First of, I will advice that you use the following in your code: `use warnings;` and `use strict;`. These two pragma, will save you a lot of headaches. Secondly, It is a lot better if your codes are divided into different parts using subroutine instead of lumpping … | |
Re: James 79, You are posting a new question under a solved trend. There is a every chance that your question would not be attended to. Because the trend already has a Solved mark. So, Please start a new disussion instead. Thank you. | |
Re: Hi, for your codes line numbered 7-11, replace with this: #open the file that contains the body of the email open(FH,'<','body.txt') or die "file does not exists $!"; my $body=do{ local $/ = undef;<FH>}; close(FH); then code line numbered 19-21 then do this: `body => $body,` it should work. | |
Re: Hi Wade_1, How are you reading the text file from with your Perl script? What are the text copied into the text file? Obviously, these will be a UTF8 charater set issue. Moreover, you don't need to copy from a webpage into a text file, before opening and reading the … | |
Re: Hi, First of, there is nothing like PERL,because perl is not an acronym. The language is Perl ( with capital letter ) and the interpreter is called perl ( with small letter ). [What's the difference between "perl" and "Perl"?](http://perldoc.perl.org/perlfaq1.html#What%27s-the-difference-between-%22perl%22-and-%22Perl%22?) That been said OOP in perl is a whole book, … | |
Re: Hi, What you have are checkboxes, which are table data of a table row. So changing the both table attributes and the row attributes could help. See a modification of your code below, and please tell us know if it works. use warnings; use strict; use CGI qw(:standard); my $q … | |
Re: Something like this: my $str='TGCTCCGGAGCGGTTGACCGACGAATCATGGTTTCGTCTACATCCCGTCTAGTTTCTAG'; while($str=~m/(TC)/g){ print $1,$/ } OR something like this (**UPDATE**): my $str = do{local $/;<DATA>}; for(split/\n/,$str){ print $_,$/ if(/It followed/ .. /till Mary/); # using range operator } __DATA__ Mary had a little lamb, whose fleece was white as snow. And everywhere that Mary went, the … | |
Re: Hello arishy, To start with NEVER use regex to parse an html file(s). It might work for a line or two, but not a file. 2. Modern Perl Mastering encourages the use of tested and used modules in the cpan or other cpan mirrors. Why will you want to re-create … | |
Re: Hi jjoseph8008, You are welcome to learning this great Programming language. I think it will help a bit if you show some codes you have written to solve this problem and where you are having difficultes. As you will not learn much if codes where just written and you don't … | |
Re: Hi, It will be better if you can share more codes here, so that we can see what you are really comparing. However, there are several things wrong with the code you have shown so far. Do you intend to use `&&` as against `&` and `||` as against `|`. … | |
Re: The code below should solve this quiet easily. #!/usr/bin/perl use warnings; use strict; my %lump_has; while (<DATA>) { chomp; my ( $title, $value ) = split; push @{ $lump_has{$title} }, $value; } print join ' ', $_, @{ $lump_has{$_} }, $/ for keys %lump_has; __DATA__ AH 1106 AH 11989 AH … | |
Re: It would have been wonderful if you show what you have tired. So that we can tell you where you are going wrong. However, this will do: Instead of writing the open function twice, I wrote just once in a subroutine. And used it to call and perform different operation … | |
Re: Hi, use int for main() and return 0. Then you could try if and else to break up a long print out like so: #include<stdio.h> #include<conio.h> int main() { int a [20], i; int count = 0; //clrscr (); printf("enter 20 numbers:"); for ( i = 0 ; i < … | |
Re: Hi, The code below solves the problem. Take this as a guide. Test, verify and ask if you still have some other questions. #!/usr/bin/perl use warnings; use strict; my $data; while (<DATA>) { chomp; my $value = substr $_, 4; # you can use regex instead push @{$data}, [ split … | |
Re: Hi d5e5, Long time. Nice solutions. It worked just as you intended. Tested it on Window OS using both ActivePerl and StrawberryPerl. Hi replic, Nice work but I didn't get your point here. >However not escaping the ''s when using '"' seems to cause a lot of problems. Try escaping … | |
Re: Or, write the for loop like so: for my $i(0..$#sessions){ ... ... ( $sessions[$i]) ... } |
The End.