Image caption The case was heard at the High Court in Edinburgh

A 12-year-old boy who raped a nine-year-old girl after viewing pornography on the internet has avoided a custodial sentence.

The High Court in Edinburgh was told the boy, who is now 14, was "emulating" the actions he had seen after having "unfettered" online access.

Defence counsel said the case could represent the "tip of the iceberg".

Judge Lady Smith said the case would be referred to the Children's Panel and the boy kept under supervision.

The boy's defence counsel, Sean Templeton said: "There is a real risk that young people of the current generation of teenagers are growing up with a skewed view of what sex is and sexual activity."

He was afforded unfettered access to the internet and it has become apparent from a very young age, the age of 12, he was accessing hard-core pornography Sean Templeton, Defence counsel

He said it was a great concern that they could be getting sex education through pornographers.

He added: "He was afforded unfettered access to the internet and it has become apparent from a very young age, the age of 12, he was accessing hard-core pornography.".

Mr Templeton said that the boy had identified the websites he visited to police. "The behaviour witnessed was reminiscent of the acts carried out by him," he said.

Lady Smith told the teenager that having looked at detailed reports prepared in his case, she could consider a non-custodial sentence.

'Behave sexually'

She told the boy he must "behave" and that he was being given an opportunity to "make something" of himself, to put his mistakes behind him and accept the wrongdoing and to think carefully of what it was like for the girl and "what she is living with because of that wrongdoing".

The judge told him: "You should not and must not regard pornography as any guide at all as to how to behave sexually."

The judge pointed out that he had pled guilty to statutory offences under the Sexual Offences (Scotland) Act 2009.

The boy, who cannot be identified for legal reasons, had earlier admitted statutory offences of rape and sexual assault committed between 1 December 2010 and 31 January 2011 at a Scottish island community.

Advocate depute, Jane Farquharson said the offences came to light after the girl complained of having a sore stomach.

She eventually asked her mother if her problem could be because she was about to have a baby. Her mother asked her if something had happened to her and she became hysterical before revealing what the boy had done.