KevinADC 192 Practically a Posting Shark

here is a link to the sprintf function that shoul dhelp you figure out what you need to do. The printf function uses the same formats as the sprintf function.

http://perldoc.perl.org/functions/sprintf.html

KevinADC 192 Practically a Posting Shark

mawe already gave you your answer, use %-5i instead of %d as the formatter.

KevinADC 192 Practically a Posting Shark

very good. I noticed this in your code:

closedir ("DIR");

You should remove the double-quotes as DIR is a filehandle. No sense in getting into bad habits. ;)

KevinADC 192 Practically a Posting Shark

disabling intellitxt too makes it adfree!

Yes, I have that disabled also. I don't like intellitext but I can sort of grimace and bear it. But since dani gives the option to turn it off I don't have to grimace.

KevinADC 192 Practically a Posting Shark

I think the dots were just for representation, he probably just wants to right pad the fields with spaces.

KevinADC 192 Practically a Posting Shark

If the crontab script is perl, use mkdir(), if it's not perl, use whatever is appropriate.

KevinADC 192 Practically a Posting Shark

I need a new car myself.

KevinADC 192 Practically a Posting Shark

Jeez christina>you, you have 2100+ posts in like 2 months? I'm speechless.

KevinADC 192 Practically a Posting Shark

Maybe its an age difference thing, me being 50 years old and you being much younger. But why do you even care that you got a bad rep in the word game forum? If I were to ever paticipate in that forum and someone actually took the time to bad rep me I think I would laugh. Even if someone bad rep'd me for no good reason in a programming forum and I actually noticed, I would be ammused. I guess you younger members take that stuff seriously?

christina>you commented: \ -1
Duki commented: .. +0
~s.o.s~ commented: Equlizer is a must. +19
KevinADC 192 Practically a Posting Shark

I wish I would have found that Ad Blocker addon long ago. It works great, the site loads way faster (on dialup) and no more obnoxious animated billboard ads. It's the best of both worlds because daniweb still gets it's money for postng ads that I and anyone else that uses a feature like ad blocker doesn't ever see. And if other people actually want to see those ads, which is beyond me, they can still look at them.

KevinADC 192 Practically a Posting Shark

one way to do it:

my %table = (
   ddr => 0,
   eth => 0
);
open (FH, "path/to/yourfile") or die "$!"; 
while(<FH>){
   if(/^ddr\./) {
      my ($col5) = /\s(\d+)$/;
      $table{ddr}+=$col5;
   }
   elsif(/^eth\./){
      my ($col5) = /\s(\d+)$/;
      $table{eth}+=$col5;
   }
   else {
      next;
   }
}
close(FH);
print "ddr = $table{ddr}\neth = $table{eth}";
KevinADC 192 Practically a Posting Shark

What have you tried so far? Is this school/class work?

KevinADC 192 Practically a Posting Shark

this part of your code isn't correct, the syntax is bad.

&usage if ( scalar @ARGV != 3){
else {
die "Too many arguments\n";
}

try like this:

use strict;
if (scalar @ARGV != 3) {
    die "Wrong number of arguments\n";
}
my ($file1, $file2, $deviation) = @ARGV;
KevinADC 192 Practically a Posting Shark

make your test simple for now:

chdir("C:/Perl/Scripts") || die "Can't chdir to C:/Perl/Scripts: $!";
opendir(DIR,"backuptest") || die "Did not open folder: $!";
my @folders = readdir DIR;
print "$_\n" for @folders;

see what that prints

KevinADC 192 Practically a Posting Shark

You should use perl to crate the directory:

mkdir("blah") or die "Can't mkdir blah: $!";

but if you are using system() examine the return value of system, see the system documentation for details:

http://perldoc.perl.org/functions/system.html

KevinADC 192 Practically a Posting Shark

use the MIME::Lite module and sending attachments is a piece of cake.

MIME::Lite

KevinADC 192 Practically a Posting Shark

you can always have the perl script chdir to the folder you are interested in:

chdir('C:/Perl/Scripts/Backuptest') or die "Can't chdir to C:/Perl/Scripts/Backuptest: $!";

Note: its safer to use forward slashes in directory paths, even if you are on windows. Windows supprts forward and back slashes in directory paths.

KevinADC 192 Practically a Posting Shark
rmdir($dir) if (-M $dir > 4);

directories have to be empty though to delete them like this. You could write a recursive function to delete all files and sub directories first or use the File::Path module (it's a core module) to delete a directory tree. Or use an operating system command to delete the directory even if not empty.

KevinADC 192 Practically a Posting Shark

makes no sense to me. Did you get this warning fixed?

Use of uninitialized value in substitution (s///) at (eval 44) line 44. [Thu Apr 19 11:31:55 2007] index.cgi: Use of uninitialized value in substitution (s///) at (eval 44) line 44."
in index.cgi

KevinADC 192 Practically a Posting Shark

the code I posted would work in Win32, but it is not complete code.

KevinADC 192 Practically a Posting Shark
opendir(DIR,'backup_folder') or die "$!";
my @folders = readdir DIR;
close(DIR);

if(scalar @folders > 4) {
   remove_some();
}
elsif (scalar @folders < 4) {
   add_some();
}
else {
   print "4 folders, do nothing";
}
	
sub remove_some {
   a sub routine to delete some folders
}

sub add_some {
   a sub routine to add some folders
}
KevinADC 192 Practically a Posting Shark

hehehe.... you're quite the dick-head aren't you. I graciously decline to "come 2 the real world and understand wat the actual proble is". Or more precisely, I know what the problem is but I'm just not going to tell you.

Best regards,
Kevin, Ruler of Kevlandia

KevinADC 192 Practically a Posting Shark

Generally posting your real ID and password is not advisable.

KevinADC 192 Practically a Posting Shark

sorry I don't know, but I hope thats not your real name and password you posted.

KevinADC 192 Practically a Posting Shark

where do I send my invoice? ;)


PS.... use the code tags to display code.

KevinADC 192 Practically a Posting Shark

sounds possible but I have no clue how to go about it.

KevinADC 192 Practically a Posting Shark

btw,

this: (\d\d){2}

translates to two digits ina row twice \d\d\d\d

you wanted:

\d{2}\/\d{2}\/\d{2}

KevinADC 192 Practically a Posting Shark

what you really want are string anchors (^$):

$result = $start_date =~ /^\d\d\/\d\d\/\d\d$/;

the way you are doing it is checking a sub string, so dd/dd/dd anywhere in the string would match (where "d" is a single digit)

KevinADC 192 Practically a Posting Shark

what does "try to run it direct" mean? Do you have perl installed on your computer? You can't run perl scripts without perl. If you are trying to run a local perl script from your browser you will also need an http server installed, setup, and running.

KevinADC 192 Practically a Posting Shark

two ways to go about it:

chdir("path/to/dir") or die "$!";
opendir (DIR, ".") or die "$!";
my @files = grep {/students_.*?\.html/}  readdir DIR;
close DIR;
{
   local @ARGV = @files;
   while(<>){
      #each file will be read line by line here
   }
}
opendir (DIR, "path/to/dir") or die "$!";
my @files = grep {/students_.*?\.html/}  readdir DIR;
close DIR;
foreach my $file (@files) {
   open(FH,"path/to/$file") or die "$!";
   while (<FH>){ 
     #read file line by line here
   }
   close(FH);
}
KevinADC 192 Practically a Posting Shark

post some code....

KevinADC 192 Practically a Posting Shark

I don't see any ads on DaniWeb anymore which is why I have started participating again. AdBlocker Plus addon for Mozilla works great. The pages load much quicker and are 100% ad free. Sorry sponsors/advertisers, but you guys should make smaller and less obnoxious ads and there would be no need to have to block them. But nope, you think more colors and more movement will get your ad noticed.... wrong. It gets them blocked.

KevinADC 192 Practically a Posting Shark

google for:

posix strftime function

you will find plenty of resources that explain the strftime function in detail and POSIX in general.

KevinADC 192 Practically a Posting Shark
use Time::Local 'timelocal_nocheck';
use POSIX 'strftime';
my $s_date = '08/01/07';
my $e_date = get_edate($s_date);
print "start date:$s_date, end date: $e_date";
sub get_edate {
   my $s_date = shift || return(0);
   my ($m,$md,$y) = $s_date =~ m|(\d+)/(\d+)/(\d+)|;
   my $epochtime = timelocal_nocheck(0, 0, 0, $md, $m-1, $y);
   return strftime("%m/%d/%y",0,0,0,(localtime($epochtime+604800))[3,4,5]);
}
KevinADC 192 Practically a Posting Shark

whats the format of the start date?

KevinADC 192 Practically a Posting Shark

this does not work because the system() function does not return the output of the process:

$command = "ps";
system $command;

You use backtiks `` or qx// to capture process output:

$output = qx/ps/;
print $output;

But on further review of interprocess communications, perldocs recommends using this safe construct:

open PS, "-|", "ps" or die $!;
print <PS>;
close PS;

or stick with the Shell module

KevinADC 192 Practically a Posting Shark

I'm not sure if this is a wise way to do this, but it should work:

$ENV{PATH}='/bin/perl:/bin/bash';
open (PS, 'ps |') or die "$!";
print <PS>;
close PS;
KevinADC 192 Practically a Posting Shark

Ahh, now that I think about it \Q does not affect $ in a regexp, so you would use the quotemeta() function or add the escape character manually like you did.

KevinADC 192 Practically a Posting Shark
#!/usr/bin/perl

$s1 = "testing $my string";
$s2 = "testing \$your string";

local ($^I, @ARGV) = ('.bak', 'file.data');
while (<>) {
        s/\Q$s1\E/$s2/g;
  print;
}
KevinADC 192 Practically a Posting Shark

It seems __END__ is a "synonym" of __DATA__

http://perldoc.perl.org/perldata.html

For compatibility with older scripts written before __DATA__ was introduced, __END__ behaves like __DATA__ in the toplevel script (but not in files loaded with require or do) and leaves the remaining contents of the file accessible via main::DATA .

KevinADC 192 Practically a Posting Shark
($parsed) = $var =~ /\{108:([^}]*)\}/;
KevinADC 192 Practically a Posting Shark

You're welcome. grep is used a lot in perl for testing lists and creating lists. 'map' is another useful function for creating lists.

KevinADC 192 Practically a Posting Shark

A simpler way:

while($accessionno ne "STOP")
{
	print " which Accession number are you searching for? ";

	chomp ($accessionno= <STDIN>);

        if (grep {$_ eq $accessionno} @arr) {
                print "congratulations the accession number is in the given list\n";
        }
	else {
		print "nothing found!\n"
	}
}

but overall that is some pretty useless code unless all you need is to know if the number is found or not.

KevinADC 192 Practically a Posting Shark

what does the data look like?
what does the number you are looking for look like?
why are you going through the array backwards?
what is $match being used for?

KevinADC 192 Practically a Posting Shark

hard to say why it's not working because in the code you posted it never prints $first_line to a file and you print to a file called "revdna.fsa" but then in your last post you mention "revdna.dat".

This line in your last code post:

substr($first_line, -1, 0)= "ComplementStrand";

is simpler written as:

$first_line .= "ComplementStrand";

KevinADC 192 Practically a Posting Shark

print it outside the loop.

open(OUT,'>' , "revdna.fsa") or die "Can't write file\n $!";
print OUT "$first_line\n";
for($i=0; $i < length($rdna);$i+=60){
$base =substr($rdna, $i, 60);
print OUT "$base\n";
}
close OUT;
KevinADC 192 Practically a Posting Shark

this line:

$rdna = reverse $cdna;

should be:

my $rdna = reverse $cdna;

KevinADC 192 Practically a Posting Shark

tr/// only replaces characters for characters (transliteration). It is very limited but faster than s/// for simple character replacing. s/// is a full blown regexp that can use all of perls various options for pattern matching and substitution.

For example if all you wanted to do was replace all A's with Z's tr is the better choice:

tr/A/Z/;

tr/// can't even use case insensitive matching so to replace all 'A' and 'a' with 'Z' you have to do this:

tr/aA/Z/;

the only useful option with tr/// is the range operator:

tr/a-z/A-Z/

besides that the three basic modifiers are:

c Complement the SEARCHLIST.
d Delete found but unreplaced characters.
s Squash duplicate replaced characters.

see:

http://perldoc.perl.org/perlop.html

for more information

KevinADC 192 Practically a Posting Shark
#!/usr/bin/perl
use strict;
use warnings;
open(IN, '<',"dna.dat") or die "Can't read file\n $!";
my $first_line = <IN>;
my $dna = '';
while(my $line=<IN>){
   chomp $line;
   $dna .= $line;
}
close IN;
my $cdna = '';
for my $i (0 .. length($dna)-1){
   $_ = substr($dna, $i, 1);
   if (!/[TAGC]/) {die "Unkown base: '$_'\n";}
   $cdna .= ($_ eq 'A') ? 'T' : 
            ($_ eq 'T') ? 'A' :
            ($_ eq 'C') ? 'G' :
            ($_ eq 'G') ? 'C' : '';
}
my $rdna = reverse $cdna;
print "The DNA string is now reversed complemented:\n\n $first_line\n$rdna\n";
KevinADC 192 Practically a Posting Shark

well, thats it for me, I'm leaving daniweb. I'll check back in the future and see if this site has improved (or gotten worse) as far as advertising goes.

All the best to daniweb.