415 Posted Topics

Member Avatar for jrp370

Your script looks up each name in a hash before inserting it into your database and saving it into the hash. That works as long as your script runs, but when it stops your hash no longer exists. The database persists when the script isn't running, so you need to …

Member Avatar for d5e5
0
115
Member Avatar for biojet

[QUOTE=biojet;1749758]...I can put out the data with [CODE] num name product star_posi end_posi 1 [gene=KIQ_00005] [protein=hypothetical [location=complement(<1..423)][/CODE] but I can not seperare the number of [location] and I can not delete [] of data...[/QUOTE]To remove the square brackets from your text string you can do a regex substitution.[CODE]#!/usr/bin/perl; use strict; …

Member Avatar for biojet
0
120
Member Avatar for Pallab.Bhk

[CODE]#!/usr/bin/perl; use strict; use warnings; my $filename1 = 'file1.txt'; my $filename2 = 'file2.txt'; my $filename3 = 'file3.txt'; #Build a hash of arrays from file2 my %uniprot_families; open my $fh, '<', $filename2 or die "Failed to open $filename2: $!"; while (my $rec = <$fh>){ chomp($rec); my ($id, $family) = split(/\s+/, $rec); …

Member Avatar for d5e5
0
95
Member Avatar for biojet

[CODE]#!/usr/bin/perl; use strict; use warnings; use Data::Dumper; my $n = 3;#Decided position my $filename = 'sample file.txt'; open my $fh, '<', $filename or die "Failed to open $filename: $!"; while (<$fh>){ next if m/^#/;#Skip comment lines my @array = (); foreach (1 .. $n){ my $rec = <$fh>; last unless …

Member Avatar for d5e5
0
269
Member Avatar for starlight849

[CODE]#!/usr/bin/perl; use strict; use warnings; printf("Dollar %s\nPound %s\nPercent %s\nCarot %s\nAmpersand %s", ('$', '#', '%', '^', '&', '*')); #Outputs #Dollar $ #Pound # #Percent % #Carot ^ #Ampersand &[/CODE]I'm not sure I understand the question. You ask about symbols occurring within the text but your example shows a percent sign occurring …

Member Avatar for starlight849
0
201
Member Avatar for biojet

You need to save your base information into a variable as you read it, and save this into one of your hashes, along with position.[CODE]#!/usr/bin/perl; use strict; use warnings; use autodie; my ( %data1, %data2 ); open my $in, '<', 'baselist.txt'; while (<$in>) { next unless /^\s*\d/; my ( $num, …

Member Avatar for biojet
0
138
Member Avatar for biojet

I don't see how your script decides whether to print 'change' or 'same'? What is the rule that determines this?

Member Avatar for d5e5
0
408
Member Avatar for Cupidvogel

[QUOTE]Every Perl expression is in one of two `contexts', either `list context' or `scalar context', depending on whether it is expected to produce a list or a scalar. Many expressions have quite different behaviors in list context than they do in scalar context.[/QUOTE] [URL="http://perl.plover.com/context.html"]http://perl.plover.com/context.html[/URL] The print command expects a list …

Member Avatar for d5e5
0
283
Member Avatar for biojet

input1.csv[CODE=text]3 ATG 2 ACT 1 ATC [/CODE] input2.csv[CODE=text]G C C A A A [/CODE] [CODE]#!/usr/bin/perl; use strict; use warnings; my ($filename1, $filename2) = ('input1.csv', 'input2.csv'); open my $fh1, '<', $filename1 or die "Failed to open $filename1: $!"; open my $fh2, '<', $filename2 or die "Failed to open $filename2: $!"; while …

Member Avatar for biojet
0
164
Member Avatar for Karlwakim

Did you run it with at least two command line arguments? When I run your script from the command line with no arguments I get the same error. But if I run it from the command line as follows:[iCODE]perl temp01.pl localhost 42;[/iCODE] it runs and prints lines until I kill …

Member Avatar for Karlwakim
0
119
Member Avatar for sandeepau

[QUOTE=sandeepau;1716386]Hello, Can someone tell me the equivalent perl script/command for following unix command: sort -t"|" -k1,1 -T '/temp' input.txt > output.txt Here, I want mention different physical directory for temprary sort file storage. like - T in unix shell command. In other word, How to mention different workspace directory in …

Member Avatar for voidyman
0
404
Member Avatar for starlight849

Could you give us a snippet of your script to illustrate what you are trying to do? Maybe it's me but I really don't understand what you mean by evaluating "variabl%e". Does the following bear any resemblance to what you want?[CODE]#!/usr/bin/perl; use strict; use warnings; my $variable = 1; my …

Member Avatar for d5e5
0
93
Member Avatar for magikman

Why do you say it doesn't compile? When I run it with options -H localhost -t load, for example, it just hangs until I kill it. I don't get any syntax errors indicating it won't compile and no runtime errors such as division by zero, so I can't reproduce the …

Member Avatar for d5e5
0
475
Member Avatar for Cupidvogel

Run Perl with the -d option and it starts in [URL="http://perldoc.perl.org/perldebug.html"]debug mode[/URL] which you can use as a command line interpreter to print out the values of expressions. The 'p' command tells the Perl debugger to print the value of the expression.[iCODE]david@david-laptop:~$ perl -de 0 Loading DB routines from perl5db.pl …

Member Avatar for d5e5
0
311
Member Avatar for sandeepau

[CODE]#!/usr/bin/perl; use strict; use warnings; my $filename = 'input.csv'; open my $fh, '<', $filename or die "Unable to open $filename: $!"; my $firstline = <$fh>; chomp($firstline); print "The first line is $firstline\n"; my @fields = split(/,/, $firstline); my $len = length($fields[1]); print "The second field contains '$fields[1]' which has length …

Member Avatar for d5e5
0
210
Member Avatar for bio-grad

[CODE]#!/usr/bin/perl; use strict; use warnings; my $pathway;#To save string from previous iteration, create variable outside loop while (my $line = <DATA>) { chomp($line); if ($line =~ /^$/) { next; } elsif ($line =~ /ko/) { $pathway = $line; } elsif ($line =~ /K/) { #trim($line); #What does your trim() subroutine …

Member Avatar for bio-grad
0
136
Member Avatar for winecoding

Building on [URL="http://www.daniweb.com/members/Trentacle/865513"]Trentacle[/URL]'s first correction of your data structure you could try the following:[CODE]#!/usr/bin/perl; use strict; use warnings; use Data::Dumper; my $chainStorage = { ACB => { E => { '06' => [100, 200, 95] }, B => { '23' => [20, 1000, 5, 30] }, }, AFG => { …

Member Avatar for d5e5
0
451
Member Avatar for ssdeep

[CODE]#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $rec = '(9430, 3656) (9147, 14355) (133, 14393) (7917, 9513) (3719, 12775)'; $rec =~ s/['(),]//g; #Remove everything except digits and spaces my %hash = split / /, $rec; #Split on space character and assign to hash print Dumper(\%hash);[/CODE]

Member Avatar for d5e5
0
229
Member Avatar for ssdeep

We can take the greatest five from a hash without sorting. I don't know if that makes it more efficient. For example, the following prints the five colors having the longest wavelengths.[CODE]#!/usr/bin/perl use strict; use warnings; my %d = (violet => 400, red => 650, indigo => 445, orange => …

Member Avatar for ssdeep
1
211
Member Avatar for sandeepau

Here's an example of sorting an array by a specified column.[CODE]#!/usr/bin/perl; use strict; use warnings; my @array = sort howtosort <DATA>; foreach (@array){ chomp; print "$_\n"; } sub howtosort{ my @flds_a = split(/\|/, $a); my @flds_b = split(/\|/, $b); $flds_a[2] cmp $flds_b[2]; #compare key fields to sort } __DATA__ 1780438|20110709|0000007704000000000000004888|7704|48881|PE|08/12/2008 …

Member Avatar for sandeepau
0
868
Member Avatar for sandeepau

[CODE]#!/usr/bin/perl use strict; use warnings; my ($file1, $file2, $file3) = qw(1.txt 2.txt 3.txt); open my $fh1, '<', $file1 or die "Can't open $file1: $!"; open my $fh2, '<', $file2 or die "Can't open $file2: $!"; open my $fh3, '>', $file3 or die "Can't open $file3: $!"; while (<$fh1>){ last if …

Member Avatar for sandeepau
0
4K
Member Avatar for ssdeep

[QUOTE=ssdeep;1704055]i want to be able to treat contents of a file as an array and traverse through it that way without having to store them in an array,can i do that?if so how?[/QUOTE] [URL="http://perldoc.perl.org/Tie/File.html"]Tie::File[/URL] treats the contents of a file as an array, but not a 2D array. You might …

Member Avatar for Dandello
0
242
Member Avatar for biojet

You need to name your DATA section [ICODE]__DATA__[/ICODE] in capital letters, not [ICODE]__data__[/ICODE]. You can skip records that don't begin with a number, as follows:[CODE]#skip non-numeric data next unless m/^\d/;[/CODE] Notice that the script ignores column 0 and starts with column 1, because in Perl array indexes begin at 0. …

Member Avatar for biojet
0
186
Member Avatar for crazyIT

Only very old versions of Perl require you to name file handles as barewords such as FILE1 etc. Use lexical filehandles instead. [QUOTE]FILEHANDLEs without sigils are a sign of ancient Perl. [URL="https://www.socialtext.net/perl5/bareword_uppercase_filehandles"]This page[/URL] aims to describe why this style was once common, what's wrong with it, and what you can …

Member Avatar for Dandello
0
158
Member Avatar for damorph

What part of the script gives you trouble? Reading a file? Splitting the data and saving them in an array? Writing a new file?

Member Avatar for d5e5
0
240
Member Avatar for uvray90

I don't have Windows, but I think that instead of using the ODBC driver you may have more success using the DBD::mysql driver. For instructions see [URL="http://cpansearch.perl.org/src/JWIED/DBD-mysql-2.1012/INSTALL.html"]How to install and configure DBD::mysql[/URL]

Member Avatar for d5e5
0
246
Member Avatar for jojobean

Post your SQL statement here, wrapped in [noparse][CODE]your SQL statement[/CODE][/noparse] tags and maybe someone here will be able see what's wrong with the syntax.

Member Avatar for d5e5
0
18
Member Avatar for boshu

For example:[CODE]#!/usr/bin/perl use strict; use warnings; use File::Find; use File::Path qw(make_path); use File::Basename; use File::Copy; my @directories_to_search = ('/home/david/Programming/data'); my @suffixes = qw(.axf .fls .txt .err .dummy .log .cfg); find(\&wanted, @directories_to_search); sub wanted{ my($filename, $directories, $suffix) = fileparse($File::Find::name, @suffixes); if ($suffix){ my $target_dir = "/home/david/test/$directories"; make_path($target_dir); copy($File::Find::name,"$target_dir/$filename$suffix") or die "Copy …

Member Avatar for d5e5
0
377
Member Avatar for biojet

Suppose file.txt contains the following:[iCODE]CTTA TAAC GACC CCCG CCGA CACG GCAG TGAG CGCA GCAG CGAC GCGT GGCT CTTG TAAT AACC AATG CGCT TGCG AAAT CAGC TAGC CCAT TTGA TAAA GTAA GGGC TCGA GAGG ATTT GGCA TTAA GCAC GGCT TGTG CCTA CCTC TGGT TTCC GTGT CTAC ACAG TAGT CGGC TGTC TATC …

Member Avatar for d5e5
0
202
Member Avatar for elcubanoluis

[iCODE]$sql = "INSERT INTO leaderboard ([COLOR="Red"]First Name[/COLOR]) VALUES ('values')";[/iCODE] When a column name contains a space you must quote it using back ticks, like this: [iCODE]$sql = "INSERT INTO leaderboard ([COLOR="Green"]`First Name`[/COLOR]) VALUES ('values')";[/iCODE]

Member Avatar for smantscheff
0
217

The End.